Skip to content

Commit 7058341

Browse files
authored
Prevent file switching from affecting undo history (#1881)
fix: prevent programmatic editor updates due to file switching from affecting undo history
1 parent cd4572e commit 7058341

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/components/sequencing/SequenceEditor.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
// both files could have identical content.
110110
if (editorSequenceView?.state.doc.toString() !== sequenceDefinition) {
111111
editorSequenceView?.dispatch({
112+
annotations: [Transaction.addToHistory.of(false)], // Prevent this change from being added to the undo history
112113
changes: { from: 0, insert: sequenceDefinition, to: editorSequenceView.state.doc.length },
113114
userEvent: 'file.open',
114115
});

src/components/ui/TextEditor.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import { standardKeymap } from '@codemirror/commands';
55
import { json, jsonParseLinter } from '@codemirror/lang-json';
66
import { linter, lintGutter } from '@codemirror/lint';
7-
import { Compartment, EditorState } from '@codemirror/state';
7+
import { Compartment, EditorState, Transaction } from '@codemirror/state';
88
import { type ViewUpdate, keymap } from '@codemirror/view';
99
import { basicSetup, EditorView } from 'codemirror';
1010
import { debounce } from 'lodash-es';
@@ -57,6 +57,7 @@
5757
// to avoid resetting the cursor position.
5858
if (editorView.state.doc.toString() !== textFileContent) {
5959
editorView.dispatch({
60+
annotations: [Transaction.addToHistory.of(false)], // Prevent this change from being added to the undo history
6061
changes: { from: 0, insert: textFileContent, to: editorView.state.doc.length },
6162
});
6263
}

0 commit comments

Comments
 (0)