Make wordwrapping toggleable with Alt+Z
This commit is contained in:
parent
4d6a2700d2
commit
ef2adbdf80
|
|
@ -1,4 +1,9 @@
|
||||||
import { Transaction, StateEffect } from "@codemirror/state";
|
import {
|
||||||
|
Transaction,
|
||||||
|
StateEffect,
|
||||||
|
Compartment,
|
||||||
|
Extension,
|
||||||
|
} from "@codemirror/state";
|
||||||
import {
|
import {
|
||||||
EditorView,
|
EditorView,
|
||||||
keymap,
|
keymap,
|
||||||
|
|
@ -44,6 +49,8 @@ export class Editor {
|
||||||
file: OpenFile;
|
file: OpenFile;
|
||||||
deleteFn?: () => void;
|
deleteFn?: () => void;
|
||||||
|
|
||||||
|
private wordWrapCompartment = new Compartment();
|
||||||
|
|
||||||
dispatch(tr: Transaction, inhibitSync = false) {
|
dispatch(tr: Transaction, inhibitSync = false) {
|
||||||
this.view.update([tr]);
|
this.view.update([tr]);
|
||||||
if (!inhibitSync) {
|
if (!inhibitSync) {
|
||||||
|
|
@ -67,6 +74,16 @@ export class Editor {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ key: "Mod-w", run: () => this.close() },
|
{ key: "Mod-w", run: () => this.close() },
|
||||||
|
{
|
||||||
|
key: "Alt-z",
|
||||||
|
run: () => {
|
||||||
|
this.toggleExt(
|
||||||
|
this.wordWrapCompartment,
|
||||||
|
EditorView.lineWrapping,
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
this.view = new EditorView({
|
this.view = new EditorView({
|
||||||
doc: file.rootState.val.doc,
|
doc: file.rootState.val.doc,
|
||||||
|
|
@ -75,7 +92,7 @@ export class Editor {
|
||||||
oneDark,
|
oneDark,
|
||||||
fixedHeightEditor,
|
fixedHeightEditor,
|
||||||
kmap,
|
kmap,
|
||||||
EditorView.lineWrapping,
|
this.wordWrapCompartment.of(EditorView.lineWrapping),
|
||||||
lineNumbers(),
|
lineNumbers(),
|
||||||
highlightSpecialChars(),
|
highlightSpecialChars(),
|
||||||
foldGutter(),
|
foldGutter(),
|
||||||
|
|
@ -119,6 +136,13 @@ export class Editor {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggleExt(compartment: Compartment, extension: Extension) {
|
||||||
|
const on = compartment.get(this.view.state) == extension;
|
||||||
|
this.view.dispatch({
|
||||||
|
effects: compartment.reconfigure(on ? [] : extension),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
setDeleteFunction(fn: () => void) {
|
setDeleteFunction(fn: () => void) {
|
||||||
this.deleteFn = fn;
|
this.deleteFn = fn;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue