mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
chore(code): stop loading unnecessary extensions for read-only mode
This commit is contained in:
parent
a20a51fa75
commit
2704548eb8
@ -37,7 +37,6 @@ export default class CodeMirror extends EditorView {
|
|||||||
extensions = [
|
extensions = [
|
||||||
...extensions,
|
...extensions,
|
||||||
languageCompartment.of([]),
|
languageCompartment.of([]),
|
||||||
historyCompartment.of(history()),
|
|
||||||
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
||||||
highlightActiveLine(),
|
highlightActiveLine(),
|
||||||
highlightSelectionMatches(),
|
highlightSelectionMatches(),
|
||||||
@ -52,22 +51,26 @@ export default class CodeMirror extends EditorView {
|
|||||||
])
|
])
|
||||||
]
|
]
|
||||||
|
|
||||||
if (config.readOnly) {
|
if (!config.readOnly) {
|
||||||
extensions.push(EditorState.readOnly.of(true));
|
// Logic specific to editable notes
|
||||||
}
|
if (config.placeholder) {
|
||||||
|
extensions.push(placeholder(config.placeholder));
|
||||||
|
}
|
||||||
|
|
||||||
if (config.placeholder) {
|
if (config.onContentChanged) {
|
||||||
extensions.push(placeholder(config.placeholder));
|
extensions.push(EditorView.updateListener.of((v) => this.#onDocumentUpdated(v)));
|
||||||
|
}
|
||||||
|
|
||||||
|
extensions.push(historyCompartment.of(history()));
|
||||||
|
} else {
|
||||||
|
// Logic specific to read-only notes
|
||||||
|
extensions.push(EditorState.readOnly.of(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.lineWrapping) {
|
if (config.lineWrapping) {
|
||||||
extensions.push(EditorView.lineWrapping);
|
extensions.push(EditorView.lineWrapping);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.onContentChanged) {
|
|
||||||
extensions.push(EditorView.updateListener.of((v) => this.#onDocumentUpdated(v)));
|
|
||||||
}
|
|
||||||
|
|
||||||
super({
|
super({
|
||||||
parent: config.parent,
|
parent: config.parent,
|
||||||
extensions
|
extensions
|
||||||
@ -101,6 +104,10 @@ export default class CodeMirror extends EditorView {
|
|||||||
* Clears the history of undo/redo. Generally useful when changing to a new document.
|
* Clears the history of undo/redo. Generally useful when changing to a new document.
|
||||||
*/
|
*/
|
||||||
clearHistory() {
|
clearHistory() {
|
||||||
|
if (this.config.readOnly) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.dispatch({
|
this.dispatch({
|
||||||
effects: [ this.historyCompartment.reconfigure([]) ]
|
effects: [ this.historyCompartment.reconfigure([]) ]
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user