diff --git a/source/content-scripts/features/markdown-toolbar.tsx b/source/content-scripts/features/markdown-toolbar.tsx index a41c44c..e2d82d3 100644 --- a/source/content-scripts/features/markdown-toolbar.tsx +++ b/source/content-scripts/features/markdown-toolbar.tsx @@ -157,7 +157,12 @@ function insertSnippet(props: Required) { 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) { markdown + textarea.value.slice(selectionEnd); + if (cursorPosition === 0) { + // If no marker was used in the snippet, then put the cursor at the + // end of the snippet. + cursorPosition = snippetLength; + } + textarea.selectionEnd = selectionEnd + cursorPosition; }