Put the cursor at the end of the snippet when no marker is used.
This commit is contained in:
parent
fd4afe9fbc
commit
e752853a58
|
@ -157,7 +157,12 @@ function insertSnippet(props: Required<Props>) {
|
|||
cursorIndex -= MarkdownSnippetMarker.SelectedCursor.length;
|
||||
}
|
||||
|
||||
if (cursorIndex === -1) {
|
||||
cursorIndex = 0;
|
||||
}
|
||||
|
||||
let cursorPosition = cursorIndex;
|
||||
const snippetLength = markdown.length;
|
||||
|
||||
// If any text has been selected, include it.
|
||||
if (selectionStart !== selectionEnd) {
|
||||
|
@ -175,5 +180,11 @@ function insertSnippet(props: Required<Props>) {
|
|||
markdown +
|
||||
textarea.value.slice(selectionEnd);
|
||||
|
||||
if (cursorPosition === 0) {
|
||||
// If no <cursor> marker was used in the snippet, then put the cursor at the
|
||||
// end of the snippet.
|
||||
cursorPosition = snippetLength;
|
||||
}
|
||||
|
||||
textarea.selectionEnd = selectionEnd + cursorPosition;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue