From bdb18c52f8aff62712c344c42a92d721602e9594 Mon Sep 17 00:00:00 2001 From: Tobias Frischmann Date: Mon, 7 Sep 2026 13:28:21 +0200 Subject: [PATCH] add strg + X shortcut --- app/composables/useMarkdownEditor.ts | 34 ++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/app/composables/useMarkdownEditor.ts b/app/composables/useMarkdownEditor.ts index 509d7b2..71cc64e 100644 --- a/app/composables/useMarkdownEditor.ts +++ b/app/composables/useMarkdownEditor.ts @@ -6,8 +6,6 @@ type State = { selectionStart: number; selectionEnd: number; text: string; - - currentLine: string; }; function continueList(state: State): string { @@ -25,20 +23,23 @@ function continueList(state: State): string { return new_text; } + const lineStart = state.text.lastIndexOf("\n", state.selectionStart - 1) + 1; + const currentLine = state.text.slice(lineStart, state.selectionStart); + // Continue checkbox lists - const checkbox = state.currentLine.match(/^(\s*[-*+])\s+(\[[ xX]\]\s+)/); + const checkbox = currentLine.match(/^(\s*[-*+])\s+(\[[ xX]\]\s+)/); if (checkbox) { return insertAtCursor(`\n${checkbox[1]} [ ] `); } // Continue unordered lists - const bullet = state.currentLine.match(/^(\s*[-*+])\s/); + const bullet = currentLine.match(/^(\s*[-*+])\s/); if (bullet) { return insertAtCursor(`\n${bullet[1]} `); } // Continue numbered lists - const numbered = state.currentLine.match(/^(\s*)(\d+)\.\s/); + const numbered = currentLine.match(/^(\s*)(\d+)\.\s/); if (numbered) { const next = Number(numbered[2]) + 1; const insert = `\n${numbered[1]}${next}. `; @@ -56,15 +57,11 @@ export function useMarkdownEditor(note: ModelRef) { const end = textarea.selectionEnd; const value = textarea.value; - const lineStart = value.lastIndexOf("\n", start - 1) + 1; - const currentLine = value.slice(lineStart, start); - const state: State = { textarea, selectionStart: start, selectionEnd: end, text: value, - currentLine, }; if (e.key === "Enter" && !e.shiftKey) { @@ -75,7 +72,24 @@ export function useMarkdownEditor(note: ModelRef) { note.value = new_note; console.log("set text"); } - } else if (e.key === "x" && e.ctrlKey) { + } else if ( + e.key === "x" && + e.ctrlKey && + state.selectionStart === state.selectionEnd + ) { + e.preventDefault(); + + const lineStart = state.text.lastIndexOf("\n", state.selectionStart - 1); + const lineEnd = state.text.indexOf("\n", state.selectionStart); + + const newText = + state.text.slice(0, lineStart) + state.text.slice(lineEnd); + note.value = newText; + + requestAnimationFrame(() => { + textarea.selectionStart = lineStart; + textarea.selectionEnd = lineStart; + }); } } -- 2.51.2