Replies: 2 comments
-
Okay, I figured it out (partially). To insert a content I needed to set a selection first or it'll isert nothing.
But how to remove all existing content from the editor? How to select everything? |
Beta Was this translation helpful? Give feedback.
0 replies
-
See #1269 (comment) const editorID = props.currentTiddler;
const { resetEditor, value: updateEditorValue } = getPlateActions(editorID);
// Add the initial value when setting up our state.
const [currentAst, setCurrentAst] = useState<Array<TNode<AnyObject>>>(deserialize(props.tiddlerText));
/** current text is only used for compare, we don't want it trigger rerender, so use ref to store it */
const currentTextRef = useRef<string>(props.tiddlerText);
// update current value from props
useEffect(() => {
// there will be cases that triple return replaced with double return (trim), cause here rerender, but I think it is ok, not so frequent
if (currentTextRef.current !== props.tiddlerText) {
const newValue = deserialize(props.tiddlerText);
setCurrentAst(newValue);
updateEditorValue(newValue);
resetEditor();
}
}, [props.tiddlerText, currentTextRef, updateEditorValue, resetEditor]);
const onChange = useDebouncedCallback(
(newValue: Array<TNode<AnyObject>>) => {
setCurrentAst(newValue);
const newText = serialize(newValue);
props.saver.onSave(newText);
currentTextRef.current = newText;
},
[props.saver.onSave],
props.saver.interval,
); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've got pre-saved Nodes[] ([{ children: [{ text: 'bla' }] },{ children: [{ text: 'bla2' }] }]) and I want to replace current editor content with my pre-saved one, but programmatically (not using initialValue). I've tried using transforms, but got an error:
TypeError: Invalid value used as weak map key
Also, I've tried to clear editor content using code described here: https://stackoverflow.com/a/68810943/4434887
But got another error:
Cannot get the end point in the node at path [] because it has no end text node.
Tried:
getPlateActions(id).resetEditor()
but it does nothing.Anyone has a working example of similar functionality?
Beta Was this translation helpful? Give feedback.
All reactions