From 66e916517ec2417f9f83e4c0ce23e313705f6980 Mon Sep 17 00:00:00 2001 From: tianyaxiang Date: Mon, 24 Feb 2025 18:31:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=82=B9=E5=87=BB=20markdown?= =?UTF-8?q?=20=E7=BC=96=E8=BE=91=E6=8C=89=E9=92=AE=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E5=88=B0=E9=A1=B6=E9=83=A8=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/editor/WechatEditor.tsx | 2 ++ .../editor/components/MarkdownToolbar.tsx | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/components/editor/WechatEditor.tsx b/src/components/editor/WechatEditor.tsx index 388814b..3232000 100644 --- a/src/components/editor/WechatEditor.tsx +++ b/src/components/editor/WechatEditor.tsx @@ -194,6 +194,7 @@ export default function WechatEditor() { const start = textarea.selectionStart const end = textarea.selectionEnd const selectedText = value.substring(start, end) + const scrollTop = textarea.scrollTop let newText = '' let newCursorPos = 0 @@ -216,6 +217,7 @@ export default function WechatEditor() { requestAnimationFrame(() => { textarea.focus() + textarea.scrollTop = scrollTop textarea.setSelectionRange(newCursorPos, newCursorPos) }) }, [value, handleEditorChange]) diff --git a/src/components/editor/components/MarkdownToolbar.tsx b/src/components/editor/components/MarkdownToolbar.tsx index fefeb29..fa5f9d4 100644 --- a/src/components/editor/components/MarkdownToolbar.tsx +++ b/src/components/editor/components/MarkdownToolbar.tsx @@ -152,11 +152,14 @@ export function MarkdownToolbar({ onInsert }: MarkdownToolbarProps) { variant="ghost" size="sm" className="h-8 w-8 p-0" - onClick={() => onInsert(buttonTool.text, { - wrap: buttonTool.wrap, - placeholder: buttonTool.placeholder, - suffix: buttonTool.suffix - })} + onClick={(e) => { + e.preventDefault() + onInsert(buttonTool.text, { + wrap: buttonTool.wrap, + placeholder: buttonTool.placeholder, + suffix: buttonTool.suffix + }) + }} > {buttonTool.icon}