1
Fork 0

Put the cursor at the end of the snippet when no marker is used.

This commit is contained in:
Bauke 2023-11-24 19:53:19 +01:00
parent fd4afe9fbc
commit e752853a58
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 11 additions and 0 deletions

View File

@ -157,7 +157,12 @@ function insertSnippet(props: Required<Props>) {
cursorIndex -= MarkdownSnippetMarker.SelectedCursor.length; cursorIndex -= MarkdownSnippetMarker.SelectedCursor.length;
} }
if (cursorIndex === -1) {
cursorIndex = 0;
}
let cursorPosition = cursorIndex; let cursorPosition = cursorIndex;
const snippetLength = markdown.length;
// If any text has been selected, include it. // If any text has been selected, include it.
if (selectionStart !== selectionEnd) { if (selectionStart !== selectionEnd) {
@ -175,5 +180,11 @@ function insertSnippet(props: Required<Props>) {
markdown + markdown +
textarea.value.slice(selectionEnd); 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; textarea.selectionEnd = selectionEnd + cursorPosition;
} }