Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/checkpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ export const createCheckpoints = getCreateFunction(
cellOrValueIsEqual(oldNew[0], newCell) &&
collIsEmpty(mapSet(row, cellId)) &&
collIsEmpty(mapSet(table, rowId)) &&
collIsEmpty(mapSet(cellsDelta, tableId))
collIsEmpty(mapSet(cellsDelta, tableId)) &&
collIsEmpty(valuesDelta)
) {
storeUnchanged();
}
Expand All @@ -342,7 +343,8 @@ export const createCheckpoints = getCreateFunction(
oldNew[1] = newValue;
if (
cellOrValueIsEqual(oldNew[0], newValue) &&
collIsEmpty(mapSet(valuesDelta, valueId))
collIsEmpty(mapSet(valuesDelta, valueId)) &&
collIsEmpty(cellsDelta)
) {
storeUnchanged();
}
Expand Down
31 changes: 31 additions & 0 deletions test/unit/core/other/checkpoints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,37 @@ describe('Basics', () => {
expect(checkpoints.getCheckpointIds()).toEqual([['0'], checkpointId, []]);
});

test.each([true, false])(
'retain mixed changes when cancelling tabular changes: %s',
(cancelTabular) => {
const id0 = checkpoints.getCheckpointIds()[1];
store.setCell('t1', 'r1', 'c1', 1).setValue('v1', 1);
expectChanges(listener, '/', [[id0], undefined, []]);
if (cancelTabular) {
store.delCell('t1', 'r1', 'c1');
} else {
store.delValue('v1');
}
expect(checkpoints.getCheckpointIds()).toEqual([[id0], undefined, []]);
expectNoChanges(listener);

const id1 = checkpoints.addCheckpoint();
expect(id1).not.toEqual(id0);
expectChanges(listener, '/', [[id0], id1, []]);
checkpoints.goBackward();
expect(store.getTables()).toEqual({});
expect(store.getValues()).toEqual({});
expectChanges(listener, '/', [[], id0, [id1]]);
checkpoints.goForward();
expect(store.getTables()).toEqual(
cancelTabular ? {} : {t1: {r1: {c1: 1}}},
);
expect(store.getValues()).toEqual(cancelTabular ? {v1: 1} : {});
expectChanges(listener, '/', [[id0], id1, []]);
expectNoChanges(listener);
},
);

test('listener stats', () => {
listener.listenToCheckpoint('/c0', '0');
expect(checkpoints.getListenerStats()).toEqual({
Expand Down