Skip to content

Commit

Permalink
Fixed issue with canceling image shortcut
Browse files Browse the repository at this point in the history
Added alt text support to images
  • Loading branch information
mdickin committed Mar 12, 2017
1 parent 13d47bc commit 55b1b43
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 16 deletions.
33 changes: 25 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
**v0.7.0**
## Version History

## v0.7.1 (March 12, 2017)

* Fixed bug with image shortcut where hitting Escape on the prompts would not cancel
* Added support for optional alt tags in images

## v0.7.0 (March 11, 2017)

* Added image shortcut (ctrl+shift+L). Thanks to [@ngtrian](https://github.com/ngtrian) for the recommendation!
* Added configuration settings to show/hide icons in the title bar.
* Added configuration settings to show/hide icons in the title bar

## v0.6.1 (February 11, 2017)

* Fixed issue with Changelog not displaying in Visual Studio Extensions gallery

## v0.6.0 (February 11, 2017)

**v0.6.0**
* Added icon. Thanks to [@LaChRiZ](https://github.com/LaChRiZ) for the contribution!
* Modified link shortcut (ctrl+L) to surround URLs with angle brackets. Thanks to [@StephD](https://github.com/StephD)
for the recommendation!

**v0.5.0**
## v0.5.0 (December 3, 2016)

* Added strikethrough shortcut. Thanks to [@seanmft](https://github.com/seanmft) for the contribution!
* Added support for block selection. This allows you to select a subset of a block of text,
and it will automatically find the start and end of the block. This applies to:
Expand All @@ -16,13 +30,16 @@ and it will automatically find the start and end of the block. This applies to:
* Tables
* Fixed bug where numbered list was adding "1" twice

**v0.4.1**
## v0.4.1 (November 17, 2016)

* Added bullets icon to title menu
* Improved ordering of menu items

**v0.4.0**
* Added title and context menu shortcuts. Menu icons taken from http://material.io/icons
## v0.4.0 (November 7, 2016)

* Added title and context menu shortcuts. Menu icons taken from <http://material.io/icons>
* Added checkbox and table commands. Thanks to [@wenbaofu](https://github.com/wenbaofu) for the recommendations!

**v0.3.0**
## v0.3.0 (August 12, 2016)

* Added header shortcuts. Thanks to [@alebaffa](https://github.com/alebaffa) for the contribution!
58 changes: 51 additions & 7 deletions lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,64 @@ function toggleLink() {
}
}


const MarkdownImageRegex = /!\[.*\]\((.+)\)/;
function toggleImage() {

var editor = vscode.window.activeTextEditor;
var selection = editor.selection;

if (editorHelpers.isAnythingSelected()) {
editorHelpers.surroundSelection('![](', ')')
if (editorHelpers.isMatch(MarkdownImageRegex)) {
//Selection is a MD link, replace it with the link text
editorHelpers.replaceSelection((text) => text.match(MarkdownImageRegex)[1])
return;
}

if (editorHelpers.isMatch(UrlRegex)) {
return vscode.window.showInputBox({
prompt: "Image alt text"
})
.then(text => {
if (text == null) return;
editorHelpers.replaceSelection((url) => "![" + text + "](" + url + ")");
});
}
}
else {

var editor = vscode.window.activeTextEditor;
var selection = editor.selection;

return getLinkText()
.then(getLinkUrl)
.then(addTags);

function getLinkText() {
if (selection.isEmpty) {
return vscode.window.showInputBox({
prompt: "Image alt text"
})
}

return Promise.resolve("")
}

function getLinkUrl(linkText) {
if (linkText == null || linkText == undefined) return;

return vscode.window.showInputBox({
prompt: "Image URL"
})
prompt: "Image URL"
})
.then((url) => {
if (!url == null) return;

editorHelpers.surroundSelection("![](" + url, ")");
return { text: linkText, url: url}
})
}

function addTags(options) {
if (!options || !options.url) return;

editorHelpers.surroundSelection("![" + options.text, "](" + options.url + ")")
}
}


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Markdown Shortcuts",
"description": "Shortcuts for Markdown editing",
"icon": "media/images/markdown-shortcuts-512x512.png",
"version": "0.7.0",
"version": "0.7.1",
"publisher": "mdickin",
"engines": {
"vscode": "^0.10.10"
Expand Down

0 comments on commit 55b1b43

Please sign in to comment.