修复编辑时滚动条的问题
This commit is contained in:
parent
9e1e70a1b6
commit
862ccfcbdd
@ -105,6 +105,7 @@ export default function WechatEditor() {
|
|||||||
setValue(newValue)
|
setValue(newValue)
|
||||||
handleEditorChange(newValue)
|
handleEditorChange(newValue)
|
||||||
|
|
||||||
|
// 使用 requestAnimationFrame 确保在下一帧恢复滚动位置和光标位置
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
if (textareaRef.current) {
|
if (textareaRef.current) {
|
||||||
textareaRef.current.scrollTop = currentPosition.scrollTop
|
textareaRef.current.scrollTop = currentPosition.scrollTop
|
||||||
|
@ -61,8 +61,15 @@ export function DesktopEditor({
|
|||||||
ref={textareaRef}
|
ref={textareaRef}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
|
const scrollTop = e.target.scrollTop;
|
||||||
onValueChange(e.target.value)
|
onValueChange(e.target.value)
|
||||||
onEditorChange(e.target.value)
|
onEditorChange(e.target.value)
|
||||||
|
// 保持滚动位置
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (textareaRef.current) {
|
||||||
|
textareaRef.current.scrollTop = scrollTop;
|
||||||
|
}
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
onScroll={e => {
|
onScroll={e => {
|
||||||
|
@ -55,8 +55,15 @@ export function MobileEditor({
|
|||||||
ref={textareaRef}
|
ref={textareaRef}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
|
const scrollTop = e.target.scrollTop;
|
||||||
onValueChange(e.target.value)
|
onValueChange(e.target.value)
|
||||||
onEditorChange(e.target.value)
|
onEditorChange(e.target.value)
|
||||||
|
// 保持滚动位置
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (textareaRef.current) {
|
||||||
|
textareaRef.current.scrollTop = scrollTop;
|
||||||
|
}
|
||||||
|
});
|
||||||
}}
|
}}
|
||||||
onScroll={e => {
|
onScroll={e => {
|
||||||
if (textareaRef.current) {
|
if (textareaRef.current) {
|
||||||
|
Loading…
Reference in New Issue
Block a user