修复点击 markdown 编辑按钮跳转到顶部的 bug
This commit is contained in:
parent
52dedb0ed6
commit
66e916517e
@ -194,6 +194,7 @@ export default function WechatEditor() {
|
|||||||
const start = textarea.selectionStart
|
const start = textarea.selectionStart
|
||||||
const end = textarea.selectionEnd
|
const end = textarea.selectionEnd
|
||||||
const selectedText = value.substring(start, end)
|
const selectedText = value.substring(start, end)
|
||||||
|
const scrollTop = textarea.scrollTop
|
||||||
|
|
||||||
let newText = ''
|
let newText = ''
|
||||||
let newCursorPos = 0
|
let newCursorPos = 0
|
||||||
@ -216,6 +217,7 @@ export default function WechatEditor() {
|
|||||||
|
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
textarea.focus()
|
textarea.focus()
|
||||||
|
textarea.scrollTop = scrollTop
|
||||||
textarea.setSelectionRange(newCursorPos, newCursorPos)
|
textarea.setSelectionRange(newCursorPos, newCursorPos)
|
||||||
})
|
})
|
||||||
}, [value, handleEditorChange])
|
}, [value, handleEditorChange])
|
||||||
|
@ -152,11 +152,14 @@ export function MarkdownToolbar({ onInsert }: MarkdownToolbarProps) {
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
className="h-8 w-8 p-0"
|
className="h-8 w-8 p-0"
|
||||||
onClick={() => onInsert(buttonTool.text, {
|
onClick={(e) => {
|
||||||
wrap: buttonTool.wrap,
|
e.preventDefault()
|
||||||
placeholder: buttonTool.placeholder,
|
onInsert(buttonTool.text, {
|
||||||
suffix: buttonTool.suffix
|
wrap: buttonTool.wrap,
|
||||||
})}
|
placeholder: buttonTool.placeholder,
|
||||||
|
suffix: buttonTool.suffix
|
||||||
|
})
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
{buttonTool.icon}
|
{buttonTool.icon}
|
||||||
</Button>
|
</Button>
|
||||||
|
Loading…
Reference in New Issue
Block a user