Overview
The move operation relocates content within the document. Can be decomposed into delete + insert for transaction grouping.
Interface
interface MoveOperation extends Operation {
type: 'move';
fromPath: Path;
toPath: Path;
length?: number; // For moving text ranges
}Usage
function moveNode(editor: Editor, fromPath: Path, toPath: Path) {
const operation: MoveOperation = {
type: 'move',
fromPath: fromPath,
toPath: toPath
};
editor.applyOperation(operation);
}
// Move can be decomposed into delete + insert
function moveAsTransaction(editor: Editor, fromPath: Path, toPath: Path) {
const tx = editor.beginTransaction();
const node = editor.getNode(fromPath);
tx.add({
type: 'deleteNode',
path: fromPath
});
tx.add({
type: 'insertNode',
path: toPath,
node: node
});
tx.commit();
}