From 112fb4cbecb7e7200931de2b9613916c72bd7eb0 Mon Sep 17 00:00:00 2001 From: mirivlad Date: Tue, 14 Jul 2026 19:13:56 +0800 Subject: [PATCH] fix: apply markdown blocks to full lines --- plugins/default-editor/frontend/src/index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/default-editor/frontend/src/index.js b/plugins/default-editor/frontend/src/index.js index 47831c7..806d528 100644 --- a/plugins/default-editor/frontend/src/index.js +++ b/plugins/default-editor/frontend/src/index.js @@ -259,11 +259,14 @@ var start = textarea.selectionStart; var end = textarea.selectionEnd; var value = textarea.value; - var selected = value.slice(start, end) || placeholder || ''; + var lineStart = value.lastIndexOf('\n', Math.max(0, start - 1)) + 1; + var lineEnd = value.indexOf('\n', end); + if (lineEnd === -1) lineEnd = value.length; + var selected = value.slice(lineStart, lineEnd) || placeholder || ''; var replacement = selected.split('\n').map(function (line) { return prefix + line; }).join('\n'); - textarea.value = value.slice(0, start) + replacement + value.slice(end); - textarea.selectionStart = start; - textarea.selectionEnd = start + replacement.length; + textarea.value = value.slice(0, lineStart) + replacement + value.slice(lineEnd); + textarea.selectionStart = lineStart; + textarea.selectionEnd = lineStart + replacement.length; textarea.dispatchEvent(new Event('input', { bubbles: true })); textarea.focus(); }