Fix undo breaking cursor location
This commit is contained in:
parent
ec40c759d3
commit
b31c05d42f
|
|
@ -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.
|
||||||
|
|
@ -4,6 +4,7 @@ import {
|
||||||
TransactionSpec,
|
TransactionSpec,
|
||||||
StateEffect,
|
StateEffect,
|
||||||
Text,
|
Text,
|
||||||
|
Transaction,
|
||||||
} from "@codemirror/state";
|
} from "@codemirror/state";
|
||||||
import { history } from "@codemirror/commands";
|
import { history } from "@codemirror/commands";
|
||||||
import { Editor } from "./editor";
|
import { Editor } from "./editor";
|
||||||
|
|
@ -74,14 +75,20 @@ export class OpenFile {
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(trs: TransactionSpec, origin?: Editor) {
|
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) {
|
if (origin) {
|
||||||
const es = this.editors.filter((e) => e !== origin);
|
const es = this.editors.filter((e) => e !== origin);
|
||||||
es.forEach((e) => e.dispatch(e.view.state.update(trs), true));
|
es.forEach((e) => e.dispatch(e.view.state.update(trs), true));
|
||||||
} else {
|
} else {
|
||||||
this.editors.forEach((e) =>
|
this.editors.forEach((e) => {
|
||||||
e.dispatch(e.view.state.update(trs), true),
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue