getWritable<T extends LexicalNode> method
T
getWritable<T extends LexicalNode>()
Returns a mutable version of this node, cloning it if necessary.
Only valid inside an update. The first write in an update clones the node into the pending state and marks it dirty; subsequent writes in the same update reuse that clone.
Implementation
T getWritable<T extends LexicalNode>() {
errorOnReadOnly();
final editor = $getActiveEditor();
final state = $getActiveEditorState();
final latest = getLatest<T>();
if (editor.cloneNotNeeded.contains(_key)) {
internalMarkNodeAsDirty(latest);
return latest;
}
final mutable = $cloneWithProperties<T>(latest);
editor.cloneNotNeeded.add(_key);
internalMarkNodeAsDirty(mutable);
state.nodeMapInternal[_key] = mutable;
return mutable;
}