toggleBlockType打破另一个块的退格

时间:2019-05-09 05:21:18

标签: reactjs draftjs

我进行了以下设置:

const [editorState, setEditorState] = React.useState<EditorState>(RichUtils.toggleBlockType(EditorState.createWithContent(blocks, decorator), style))
    const estate = RichUtils.getCurrentBlockType(editorState)
    if (estate !== style)
       setEditorState(RichUtils.toggleBlockType(editorState, style))

return <>
    <div onClick={() => {
        editorRef.current!.focus()
    }}>
        <Editor
            ref={editorRef}
            editorState={editorState} onChange={(newState) => {
                if (isPreviewMode) {
                    return;
                }
               const nextStyle = RichUtils.getCurrentBlockType(newState)
                if (nextStyle !== style)
                   newState = RichUtils.toggleBlockType(newState, style)
                const newRaw = convertToRaw(newState.getCurrentContent())


   setEditorState(newState)
                }} />

想法是,块类型应该始终是我想要的块类型(即标头,段落等)-因此,如果将其关闭,它将切换为所需的块类型。

问题是,如果我在两个区块上都这样写文本:

abc 
123

如果我尝试将123退格到abc,则光标会停留在abc的第一个空行上。

0 个答案:

没有答案