修复点击 markdown 编辑按钮跳转到顶部的 bug

This commit is contained in:
tianyaxiang 2025-02-24 18:31:33 +08:00
parent 52dedb0ed6
commit 66e916517e
2 changed files with 10 additions and 5 deletions

View File

@ -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])

View File

@ -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}
</Button>