Fix undo breaking cursor location

This commit is contained in:
Quinten Kock 2025-11-10 02:15:55 +01:00
parent ec40c759d3
commit b31c05d42f
2 changed files with 15 additions and 4 deletions

4
README.md Normal file
View File

@ -0,0 +1,4 @@
# Miller code editor
This is a code editor/IDE based on CodeMirror.
Its primary goal is to provide the user with a stack/column-based navigation history, making codebase navigation easier without getting lost.

View File

@ -4,6 +4,7 @@ import {
TransactionSpec,
StateEffect,
Text,
Transaction,
} from "@codemirror/state";
import { history } from "@codemirror/commands";
import { Editor } from "./editor";
@ -74,14 +75,20 @@ export class OpenFile {
}
dispatch(trs: TransactionSpec, origin?: Editor) {
this.rootState.val = this.rootState.val.update(trs).state;
let transaction = this.rootState.val.update(trs);
this.rootState.val = transaction.state;
if (origin) {
const es = this.editors.filter((e) => e !== origin);
es.forEach((e) => e.dispatch(e.view.state.update(trs), true));
} else {
this.editors.forEach((e) =>
e.dispatch(e.view.state.update(trs), true),
);
this.editors.forEach((e) => {
let changes = transaction.changes;
let userEvent = transaction.annotation(Transaction.userEvent);
let annotations = userEvent
? [Transaction.userEvent.of(userEvent)]
: [];
e.dispatch(e.view.state.update({ changes, annotations }), true);
});
}
}