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}