From 334650756d2f80c052f4d3f1f84b2a302a97149d Mon Sep 17 00:00:00 2001 From: Aliaksei Ladyha Date: Tue, 27 Oct 2020 16:01:46 +0300 Subject: [PATCH] Fix table edit history Save the correct table state to the history upon edit. Whenever an edit to a cell is begun, the pre-edit state is now saved to the history so that a restore is possible (via undo button). --- src/core/data_proxy.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/core/data_proxy.js b/src/core/data_proxy.js index c931b1d3..abb542f9 100644 --- a/src/core/data_proxy.js +++ b/src/core/data_proxy.js @@ -347,6 +347,8 @@ export default class DataProxy { this.exceptRowSet = new Set(); this.sortedRowMap = new Map(); this.unsortedRowMap = new Map(); + this.currentEditRowIdx = null; + this.currentEditColIdx = null; } addValidation(mode, ref, validator) { @@ -964,14 +966,30 @@ export default class DataProxy { return this.getCellStyleOrDefault(ri, ci); } + isStartEditing(rowIdx, colIdx) { + if (this.currentEditRowIdx === null && this.currentEditColIdx === null) { + this.currentEditRowIdx = rowIdx; + this.currentEditColIdx = colIdx; + return true; + } + return false; + } + + stopEditing() { + this.currentEditRowIdx = null; + this.currentEditColIdx = null; + } + // state: input | finished setCellText(ri, ci, text, state) { const { rows, history, validations } = this; if (state === 'finished') { - rows.setCellText(ri, ci, ''); - history.add(this.getData()); rows.setCellText(ri, ci, text); + this.stopEditing(); } else { + if (this.isStartEditing(ri, ci)) { + history.add(this.getData()); + } rows.setCellText(ri, ci, text); this.change(this.getData()); }