我的目标
:让我的编辑器预先填充一些默认文本和不可变实体。将成为实体的文本部分将是与列表匹配的字符串({{ immutable1 }}
,{{ immutable2 }}
等)。如果某人在编辑器中键入与预定义标记列表匹配的字符串,则他们刚刚键入的字符串将立即被修饰并设置为不可变实体。问题
:当预填充到编辑器中的默认文本包含标记在多个块中时,它会中断,并且似乎将标记从最后一个块添加到第一个块中。我通过这种方式以初始状态填充编辑器:const blocksFromHTML = convertFromHTML(DEFAULT_TEXT)
const state = ContentState.createFromBlockArray(
blocksFromHTML.contentBlocks,
blocksFromHTML.entityMap
)
const [editorState, setEditorState] = React.useState(
EditorState.createWithContent(
state,
compositeDecorator
)
)
...
<Editor
editorState={editorState}
onChange={handleChange}
/>
此DEFAULT_TEXT正常工作:
DEFAULT_TEXT = 'This is the first block {{ immutable1 }} with some tokens {{ immutable2 }}
This is 2nd block with no tokens. This works fine.
The tokens are immutable and if you type more then they will become immutable too'
此DEFAULT_TEXT破坏了它:
DEFAULT_TEXT = 'This is the first block {{ immutable1 }} with some tokens {{ immutable2 }}
This 2nd block has a token {{ immutable3 }}. Apparently having a token in more than one block causes this issue.
Click anywhere in the editor and it will act erratically and add tokens.'
:转到下面的我的codeandbox链接,然后单击编辑器中的任意位置。出于某种原因,您会看到它在第一个块中添加了标记如何复制
{{ immutable1 }}
和{{ immutable3 }}
。如果您希望它正常运行,请在第33行注释掉。代码在这里:https://codesandbox.io/s/distracted-lewin-quwcr?file=/src/App.tsx我的目标:让我的编辑器预先填充一些默认文本和不可变的实体。将成为实体的文本部分将是与列表匹配的字符串({{immutable1}},{{...