基本上,我想创建可以从头开始更新的内联,如果有光标/选择的话。但是,这似乎是最重要的更改,例如从最后删除内联。
我正在尝试做类似的事情(在slate-sticky-inline的指导下)
JSFiddle或我认为的以下相关代码
const onChange = change => {
//Not in a inline but at the start of some node
if (!change.value.focusInline && change.value.selection.focusOffset === 0) {
//Find the index of the node
const textNodeIndex = change.value.focusBlock.nodes.findIndex(
node => node.key === change.value.focusText.key
);
//check the node before it to see if its an inline
const upcomingNode = change.value.focusBlock.nodes.get(textNodeIndex - 1);
if (Inline.isInline(upcomingNode)) {
//put me at the end of the inline
return change.extendToEndOf(upcomingNode);
}
}
};
我希望有人能帮助我了解这里出了什么问题,并可能解释我的误解。我还创建了一个barebones jsfiddle with my plugin。您会发现,如果尝试在“ @help”末尾删除“ p”,将会阻止您这样做。
答案 0 :(得分:0)
您忘记使用onChange函数中的this.setState({value: change.value})
。
Slate编辑器应视为受控组件。