Move Operation

노드 또는 콘텐츠를 다른 위치로 이동합니다.

개요

Move operation은 문서 내에서 콘텐츠를 재배치합니다. Transaction 그룹화를 위해 delete + insert로 분해할 수 있습니다.

인터페이스

interface MoveOperation extends Operation {
  type: 'move';
  fromPath: Path;
  toPath: Path;
  length?: number; // 텍스트 범위 이동용
}

사용법

function moveNode(editor: Editor, fromPath: Path, toPath: Path) {
  const operation: MoveOperation = {
    type: 'move',
    fromPath: fromPath,
    toPath: toPath
  };
  
  editor.applyOperation(operation);
}

// Move는 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();
}