markdown shortcuts: Set cursor position for link insertion shortcut.

For link insertion shortcut without text selection,set the cursor
position between "[]" rather than selecting "url" in "[](url)" string.
This commit is contained in:
YJDave
2018-02-01 23:39:37 +05:30
committed by Tim Abbott
parent dbefdad0ab
commit ff8be1ac94

View File

@@ -713,6 +713,7 @@ exports.handle_keydown = function (event) {
// where "url" should be automatically selected. // where "url" should be automatically selected.
// Position of cursor depends on whether browser supports exec // Position of cursor depends on whether browser supports exec
// command or not. So set cursor position accrodingly. // command or not. So set cursor position accrodingly.
if (range.length > 0) {
if (document.queryCommandEnabled('insertText')) { if (document.queryCommandEnabled('insertText')) {
txt.selectionStart = position - 4; txt.selectionStart = position - 4;
txt.selectionEnd = position - 1; txt.selectionEnd = position - 1;
@@ -720,6 +721,9 @@ exports.handle_keydown = function (event) {
txt.selectionStart = position + range.length + 3; txt.selectionStart = position + range.length + 3;
txt.selectionEnd = position + range.length + 6; txt.selectionEnd = position + range.length + 6;
} }
} else {
textarea.caret(textarea.caret() - 6);
}
} }
compose_ui.autosize_textarea(); compose_ui.autosize_textarea();