Delete Backward Operation

Delete content before the cursor position.

Overview

The delete backward operation removes content before the cursor. Typically triggered by Backspace key.

Interface

interface DeleteBackwardOperation extends Operation {
  type: 'deleteBackward';
  path: Path;
  unit: 'character' | 'word' | 'line';
  deletedContent?: any;
}

Usage

function deleteBackward(editor: Editor, position: Path, unit: 'character' | 'word' = 'character') {
  const operation: DeleteBackwardOperation = {
    type: 'deleteBackward',
    path: position,
    unit,
    deletedContent: editor.getContentBefore(position, unit)
  };
  
  editor.applyOperation(operation);
}

// Inverse: Re-insert deleted content
const inverse = {
  type: 'insertText',
  path: [position[0], position[1] - 1],
  text: operation.deletedContent
};