Overview
The remove format operation removes formatting from a text range, storing the previous value for undo.
Interface
interface RemoveFormatOperation extends Operation {
type: 'removeFormat';
path: Path;
length: number;
format: string;
previousValue?: any; // Store previous value for undo
}Usage
function removeBold(editor: Editor, selection: Selection) {
const operation: RemoveFormatOperation = {
type: 'removeFormat',
path: selection.start,
length: selection.length,
format: 'bold',
previousValue: editor.hasFormat(selection, 'bold')
};
editor.applyOperation(operation);
}
// Inverse: Re-apply format
const inverse = {
type: 'applyFormat',
path: selection.start,
length: selection.length,
format: 'bold',
value: operation.previousValue
};