ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.9k stars 3.25k forks source link

Cursor move backward on re-render while composing Chinese #5398

Open lovebzhou opened 1 year ago

lovebzhou commented 1 year ago
const MyEditor = ({data, onChange}) => {
  const [value, setValue] = useState(data)

  const [editor] = useState(() => withReact(createEditor()))

  if (ReactEditor.isComposing(editor)) {
    console.debug('#cursor backword#')
  }

  return (
    <Slate editor={editor} value={value} onChange={onChange}>
      <Editable key="demo-editable" />
    </Slate>
  )
}

const MyEditorDemo = () => {
  const [value, setValue] = useState(initialValue)
  const _onChange = useCallback(content => {
   // demo for some external change
    _.delay(() => setValue(content), 1000)
  }, [])
  return <MyEditor key="demo-my-editor" data={value} onChange={_onChange} />
}

Environment

lovebzhou commented 1 year ago

version rollback, it works.

    "slate-react": "~0.81.0",
lovebzhou commented 1 year ago

slate-react@0.81.0

image

slate-react@newer

image
zerosoul commented 1 year ago

@lovebzhou how to fix ? I'm facing the same question

lovebzhou commented 1 year ago

@lovebzhou how to fix ? I'm facing the same question

降级到 slate-react@0.81.0-,新版本少了正在编辑时(ReactEditor.isComposing)忽略组件刷新逻辑

yiqingfeng commented 1 year ago

可以尝试利用 patch-package 自己打补丁