Skip to content

Commit 97ccbb4

Browse files
committed
test: update refreshText assertions for new undo-preserving behavior
Editor._resetText now uses cm.replaceRange instead of cm.setValue + cm.clearHistory so external content reloads (Revert, FileSyncManager, AI hook flow) leave the undo stack intact and the user can ctrl-z back to their pre-reset content. Update the two affected assertions in Document-integ-test.js: - 'should clear dirty flag AND undo when text reset' renamed to 'should clear dirty flag but preserve undo history when text reset'; expects undo size 2 (original Foo edit + refreshText replaceRange) instead of 0. - The clean-text-reset case now expects undo size 1 (the single replaceRange the new code performs) instead of 0. The third pre-existing same-text and same-text-different-line-endings tests already expect history NOT to be cleared (because _resetText short-circuits when content matches), so they still pass unchanged.
1 parent 44bd5b5 commit 97ccbb4

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

test/spec/Document-integ-test.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ define(function (require, exports, module) {
117117
DocumentManager.off("dirtyFlagChange", dirtyFlagListener);
118118
});
119119

120-
it("should clear dirty flag AND undo when text reset", async function () {
120+
it("should clear dirty flag but preserve undo history when text reset", async function () {
121121
let dirtyFlagListener = jasmine.createSpy(),
122122
changeListener = jasmine.createSpy();
123123
DocumentManager.on("dirtyFlagChange", dirtyFlagListener);
@@ -137,10 +137,15 @@ define(function (require, exports, module) {
137137
expect(dirtyFlagListener.calls.count()).toBe(1);
138138
expect(changeListener.calls.count()).toBe(1);
139139

140-
// Reset text (e.g. called by Revert command, or syncing external changes)
140+
// Reset text (e.g. called by Revert command, or syncing external changes).
141+
// Editor._resetText now uses replaceRange instead of setValue+clearHistory
142+
// so the user can ctrl-z back to their pre-revert state. markClean
143+
// still resets the dirty flag relative to the new generation.
141144
doc.refreshText("New content", Date.now());
142145
expect(doc.isDirty).toBe(false);
143-
expect(doc._masterEditor._codeMirror.historySize().undo).toBe(0); // undo history GONE
146+
// Undo history is PRESERVED — the refreshText replaceRange adds a
147+
// second entry on top of the original "Foo" edit.
148+
expect(doc._masterEditor._codeMirror.historySize().undo).toBe(2);
144149
expect(dirtyFlagListener.calls.count()).toBe(2);
145150
expect(changeListener.calls.count()).toBe(2);
146151

@@ -165,7 +170,9 @@ define(function (require, exports, module) {
165170

166171
doc.refreshText("New content", Date.now()); // e.g. syncing external changes
167172
expect(doc.isDirty).toBe(false);
168-
expect(doc._masterEditor._codeMirror.historySize().undo).toBe(0); // still no undo history
173+
// The replaceRange used by Editor._resetText records one undo entry
174+
// so the user can ctrl-z back to the pre-reset content.
175+
expect(doc._masterEditor._codeMirror.historySize().undo).toBe(1);
169176
expect(dirtyFlagListener.calls.count()).toBe(0); // isDirty hasn't changed
170177
expect(changeListener.calls.count()).toBe(1); // but still counts as a content change
171178

0 commit comments

Comments
 (0)