개요
Remove format operation은 텍스트 범위에서 서식을 제거하며, undo를 위해 이전 값을 저장합니다.
인터페이스
interface RemoveFormatOperation extends Operation {
type: 'removeFormat';
path: Path;
length: number;
format: string;
previousValue?: any; // undo를 위해 이전 값 저장
}사용법
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);
}
// 역: 서식 재적용
const inverse = {
type: 'applyFormat',
path: selection.start,
length: selection.length,
format: 'bold',
value: operation.previousValue
};