mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-19 02:10:04 +08:00
fix(code): history of undo/redo preserved across notes
This commit is contained in:
parent
a4054dfa42
commit
9c8126016e
@ -1,3 +1,4 @@
|
||||
import type FNote from "../../entities/fnote.js";
|
||||
import options from "../../services/options.js";
|
||||
import TypeWidget from "./type_widget.js";
|
||||
import CodeMirror, { type EditorConfig } from "@triliumnext/codemirror";
|
||||
@ -55,22 +56,12 @@ export default class AbstractCodeTypeWidget extends TypeWidget {
|
||||
/**
|
||||
* Must be called by the derived classes in `#doRefresh(note)` in order to react to changes.
|
||||
*
|
||||
* @param {*} note the note that was changed.
|
||||
* @param {*} content the new content of the note.
|
||||
* @param the note that was changed.
|
||||
* @param new content of the note.
|
||||
*/
|
||||
_update(note: { mime: string }, content: string) {
|
||||
_update(note: FNote, content: string) {
|
||||
this.codeEditor.setText(content);
|
||||
// this.codeEditor.clearHistory();
|
||||
|
||||
// let info = CodeMirror.findModeByMIME(note.mime);
|
||||
// if (!info) {
|
||||
// // Switch back to plain text if CodeMirror does not have a mode for whatever MIME type we're editing.
|
||||
// // To avoid inheriting a mode from a previously open code note.
|
||||
// info = CodeMirror.findModeByMIME("text/plain");
|
||||
// }
|
||||
|
||||
// this.codeEditor.setOption("mode", info.mime);
|
||||
// CodeMirror.autoLoadMode(this.codeEditor, info.mode);
|
||||
this.codeEditor.clearHistory();
|
||||
}
|
||||
|
||||
show() {
|
||||
|
@ -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 = [];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user