Skip to content

Commit 55b1b43

Browse files
committed
Fixed issue with canceling image shortcut
Added alt text support to images
1 parent 13d47bc commit 55b1b43

File tree

3 files changed

+77
-16
lines changed

3 files changed

+77
-16
lines changed

CHANGELOG.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
**v0.7.0**
1+
## Version History
2+
3+
## v0.7.1 (March 12, 2017)
4+
5+
* Fixed bug with image shortcut where hitting Escape on the prompts would not cancel
6+
* Added support for optional alt tags in images
7+
8+
## v0.7.0 (March 11, 2017)
9+
210
* Added image shortcut (ctrl+shift+L). Thanks to [@ngtrian](https://github.com/ngtrian) for the recommendation!
3-
* Added configuration settings to show/hide icons in the title bar.
11+
* Added configuration settings to show/hide icons in the title bar
12+
13+
## v0.6.1 (February 11, 2017)
14+
15+
* Fixed issue with Changelog not displaying in Visual Studio Extensions gallery
16+
17+
## v0.6.0 (February 11, 2017)
418

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

10-
**v0.5.0**
23+
## v0.5.0 (December 3, 2016)
24+
1125
* Added strikethrough shortcut. Thanks to [@seanmft](https://github.com/seanmft) for the contribution!
1226
* Added support for block selection. This allows you to select a subset of a block of text,
1327
and it will automatically find the start and end of the block. This applies to:
@@ -16,13 +30,16 @@ and it will automatically find the start and end of the block. This applies to:
1630
* Tables
1731
* Fixed bug where numbered list was adding "1" twice
1832

19-
**v0.4.1**
33+
## v0.4.1 (November 17, 2016)
34+
2035
* Added bullets icon to title menu
2136
* Improved ordering of menu items
2237

23-
**v0.4.0**
24-
* Added title and context menu shortcuts. Menu icons taken from http://material.io/icons
38+
## v0.4.0 (November 7, 2016)
39+
40+
* Added title and context menu shortcuts. Menu icons taken from <http://material.io/icons>
2541
* Added checkbox and table commands. Thanks to [@wenbaofu](https://github.com/wenbaofu) for the recommendations!
2642

27-
**v0.3.0**
43+
## v0.3.0 (August 12, 2016)
44+
2845
* Added header shortcuts. Thanks to [@alebaffa](https://github.com/alebaffa) for the contribution!

lib/commands.js

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,64 @@ function toggleLink() {
200200
}
201201
}
202202

203+
204+
const MarkdownImageRegex = /!\[.*\]\((.+)\)/;
203205
function toggleImage() {
206+
207+
var editor = vscode.window.activeTextEditor;
208+
var selection = editor.selection;
209+
204210
if (editorHelpers.isAnythingSelected()) {
205-
editorHelpers.surroundSelection('![](', ')')
211+
if (editorHelpers.isMatch(MarkdownImageRegex)) {
212+
//Selection is a MD link, replace it with the link text
213+
editorHelpers.replaceSelection((text) => text.match(MarkdownImageRegex)[1])
214+
return;
215+
}
216+
217+
if (editorHelpers.isMatch(UrlRegex)) {
218+
return vscode.window.showInputBox({
219+
prompt: "Image alt text"
220+
})
221+
.then(text => {
222+
if (text == null) return;
223+
editorHelpers.replaceSelection((url) => "![" + text + "](" + url + ")");
224+
});
225+
}
206226
}
207-
else {
227+
228+
var editor = vscode.window.activeTextEditor;
229+
var selection = editor.selection;
230+
231+
return getLinkText()
232+
.then(getLinkUrl)
233+
.then(addTags);
234+
235+
function getLinkText() {
236+
if (selection.isEmpty) {
237+
return vscode.window.showInputBox({
238+
prompt: "Image alt text"
239+
})
240+
}
241+
242+
return Promise.resolve("")
243+
}
244+
245+
function getLinkUrl(linkText) {
246+
if (linkText == null || linkText == undefined) return;
247+
208248
return vscode.window.showInputBox({
209-
prompt: "Image URL"
210-
})
249+
prompt: "Image URL"
250+
})
211251
.then((url) => {
212-
if (!url == null) return;
213-
214-
editorHelpers.surroundSelection("![](" + url, ")");
252+
return { text: linkText, url: url}
215253
})
216254
}
255+
256+
function addTags(options) {
257+
if (!options || !options.url) return;
258+
259+
editorHelpers.surroundSelection("![" + options.text, "](" + options.url + ")")
260+
}
217261
}
218262

219263

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "Markdown Shortcuts",
44
"description": "Shortcuts for Markdown editing",
55
"icon": "media/images/markdown-shortcuts-512x512.png",
6-
"version": "0.7.0",
6+
"version": "0.7.1",
77
"publisher": "mdickin",
88
"engines": {
99
"vscode": "^0.10.10"

0 commit comments

Comments
 (0)