import { ICommand } from 'valor-unistore-undo'; import { SpreadSheetRuntime } from '../RuntimeContext'; import { ISelection, IStoreState } from '../index.data'; // import { clearSelection } from '../store/actions/selection'; interface IUndoContext { lastSelection: ISelection | null; } class ClearSelectionCommand extends ICommand { execute = () => { const state = this.store.getState(); this.undoContext.lastSelection = { selectionType: state.selectionType, selectedCellRange: state.selectedCellRange, selectedRowRange: state.selectedRowRange, selectedColumnRange: state.selectedColumnRange, }; this.runtime!.fsmService.send({ type: 'SELECT.NONE' }); // const patchState = clearSelection(state); // this.store.setState(patchState); return true; }; undo = () => { if (!this.undoContext.lastSelection) return; this.store.setState(this.undoContext.lastSelection as IStoreState); }; } export default ClearSelectionCommand;