修复编辑时滚动条的问题
This commit is contained in:
parent
9e1e70a1b6
commit
862ccfcbdd
@ -105,6 +105,7 @@ export default function WechatEditor() {
|
||||
setValue(newValue)
|
||||
handleEditorChange(newValue)
|
||||
|
||||
// 使用 requestAnimationFrame 确保在下一帧恢复滚动位置和光标位置
|
||||
requestAnimationFrame(() => {
|
||||
if (textareaRef.current) {
|
||||
textareaRef.current.scrollTop = currentPosition.scrollTop
|
||||
|
@ -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 => {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user