我正在关注https://docs.slatejs.org/walkthroughs/04-applying-custom-formatting上的石板教程
有一个函数调用 Text.isText(n),我不断收到 Type:Error Text.isText is not a function
toggleBoldMark(editor) {
const isActive = CustomEditor.isBoldMarkActive(editor)
Transforms.setNodes(
editor,
{ bold: isActive ? null : true },
{ match: n => Text.isText(n), split: true }
)
},
Run Code Online (Sandbox Code Playgroud) 我试图将复制的片段onCopy徒劳地放入钩子中。
我一直在尝试 event.clipboardData...
const { clipboardData } = event;
const encoded = clipboardData.getData("application/x-slate-fragment");
Run Code Online (Sandbox Code Playgroud)
但它似乎是空的。我也尝试过使用getEventTransferutils。但它返回{type: 'unknow'}
这是我一直在测试的CodeSandBox。
I'm trying to move the cursor in react slate-editor.
I tried to do it in 2 ways.
First:
// This code saving key in offset in variables
const nativeSelection = this.getSelectedText();
const nativeRange = nativeSelection.getRangeAt(0);
const range = findRange(nativeRange, this.editor);
const offset = nativeRange.endOffset;
const key = range.anchor.key;
// OnChange is triggered by running the next line and cursor moves back
this.editor.blur();
// Trying to move to the cursor
this.editor.moveTo(key, offset);
Run Code Online (Sandbox Code Playgroud)
Second:
const nativeSelection = this.getSelectedText();
const nativeRange = nativeSelection.getRangeAt(0); …Run Code Online (Sandbox Code Playgroud)