mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 03:16:11 +01:00
fix(code): history of undo/redo preserved across notes
This commit is contained in:
@@ -17,18 +17,21 @@ export default class CodeMirror extends EditorView {
|
||||
|
||||
private config: EditorConfig;
|
||||
private languageCompartment: Compartment;
|
||||
private historyCompartment: Compartment;
|
||||
|
||||
constructor(config: EditorConfig) {
|
||||
const languageCompartment = new Compartment();
|
||||
const historyCompartment = new Compartment();
|
||||
|
||||
let extensions = [
|
||||
languageCompartment.of([]),
|
||||
historyCompartment.of(history()),
|
||||
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
||||
highlightActiveLine(),
|
||||
highlightSelectionMatches(),
|
||||
bracketMatching(),
|
||||
lineNumbers(),
|
||||
indentUnit.of(" ".repeat(4)),
|
||||
history(),
|
||||
keymap.of([
|
||||
...defaultKeymap,
|
||||
...historyKeymap,
|
||||
@@ -58,6 +61,7 @@ export default class CodeMirror extends EditorView {
|
||||
});
|
||||
this.config = config;
|
||||
this.languageCompartment = languageCompartment;
|
||||
this.historyCompartment = historyCompartment;
|
||||
}
|
||||
|
||||
#onDocumentUpdated(v: ViewUpdate) {
|
||||
@@ -80,6 +84,18 @@ export default class CodeMirror extends EditorView {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the history of undo/redo. Generally useful when changing to a new document.
|
||||
*/
|
||||
clearHistory() {
|
||||
this.dispatch({
|
||||
effects: [ this.historyCompartment.reconfigure([]) ]
|
||||
});
|
||||
this.dispatch({
|
||||
effects: [ this.historyCompartment.reconfigure(history())]
|
||||
});
|
||||
}
|
||||
|
||||
async setMimeType(mime: string) {
|
||||
const newExtension = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user