修复编辑时滚动条的问题

This commit is contained in:
tianyaxiang 2025-02-04 17:47:44 +08:00
parent 9e1e70a1b6
commit 862ccfcbdd
3 changed files with 15 additions and 0 deletions

View File

@ -105,6 +105,7 @@ export default function WechatEditor() {
setValue(newValue)
handleEditorChange(newValue)
// 使用 requestAnimationFrame 确保在下一帧恢复滚动位置和光标位置
requestAnimationFrame(() => {
if (textareaRef.current) {
textareaRef.current.scrollTop = currentPosition.scrollTop

View File

@ -61,8 +61,15 @@ export function DesktopEditor({
ref={textareaRef}
value={value}
onChange={e => {
const scrollTop = e.target.scrollTop;
onValueChange(e.target.value)
onEditorChange(e.target.value)
// 保持滚动位置
requestAnimationFrame(() => {
if (textareaRef.current) {
textareaRef.current.scrollTop = scrollTop;
}
});
}}
onKeyDown={onKeyDown}
onScroll={e => {

View File

@ -55,8 +55,15 @@ export function MobileEditor({
ref={textareaRef}
value={value}
onChange={e => {
const scrollTop = e.target.scrollTop;
onValueChange(e.target.value)
onEditorChange(e.target.value)
// 保持滚动位置
requestAnimationFrame(() => {
if (textareaRef.current) {
textareaRef.current.scrollTop = scrollTop;
}
});
}}
onScroll={e => {
if (textareaRef.current) {