Skip to content

Build your personal knowledge base with Trilium Notes

chore(code): reintroduce vim keybindings

Elian Doran9b958fc659c2
diff --git a/apps/client/src/widgets/type_widgets/editable_code.ts b/apps/client/src/widgets/type_widgets/editable_code.ts
index 5bc9bc65ea..339caada85 100644
--- a/apps/client/src/widgets/type_widgets/editable_code.ts
+++ b/apps/client/src/widgets/type_widgets/editable_code.ts
@@ -45,13 +45,13 @@ export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget {
getExtraOpts(): Partial<EditorConfig> {
return {
placeholder: t("editable_code.placeholder"),
+ vimKeybindings: options.is("vimKeymapEnabled"),
onContentChanged: () => this.spacedUpdate.scheduleUpdate()
}
}
// getExtraOpts(): Partial<CodeMirrorOpts> {
// return {
- // keyMap: options.is("vimKeymapEnabled") ? "vim" : "default",
// lint: true,
// gutters: ["CodeMirror-lint-markers"],
// tabindex: 300,
diff --git a/packages/codemirror/package.json b/packages/codemirror/package.json
index 5fdace8a1c..6982b5f29a 100644
--- a/packages/codemirror/package.json
+++ b/packages/codemirror/package.json
@@ -31,6 +31,7 @@
"@codemirror/legacy-modes": "6.5.1",
"@codemirror/search": "6.5.10",
"@codemirror/view": "6.36.7",
+ "@replit/codemirror-vim": "6.3.0",
"@ssddanbrown/codemirror-lang-smarty": "1.0.0",
"@ssddanbrown/codemirror-lang-twig": "1.0.0",
"codemirror-lang-hcl": "0.1.0",
diff --git a/packages/codemirror/src/index.ts b/packages/codemirror/src/index.ts
index 71168938c7..6bf586437c 100644
--- a/packages/codemirror/src/index.ts
+++ b/packages/codemirror/src/index.ts
@@ -3,6 +3,7 @@ import { EditorView, highlightActiveLine, keymap, lineNumbers, placeholder, View
import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting, indentUnit, bracketMatching } from "@codemirror/language";
import { Compartment, type Extension } from "@codemirror/state";
import { highlightSelectionMatches } from "@codemirror/search";
+import { vim } from "@replit/codemirror-vim";
import byMimeType from "./syntax_highlighting.js";
type ContentChangedListener = () => void;
@@ -10,6 +11,7 @@ type ContentChangedListener = () => void;
export interface EditorConfig extends EditorViewConfig {
placeholder?: string;
lineWrapping?: boolean;
+ vimKeybindings?: boolean;
onContentChanged?: ContentChangedListener;
}
@@ -23,7 +25,14 @@ export default class CodeMirror extends EditorView {
const languageCompartment = new Compartment();
const historyCompartment = new Compartment();
- let extensions = [
+ let extensions: Extension[] = [];
+
+ if (config.vimKeybindings) {
+ extensions.push(vim());
+ }
+
+ extensions = [
+ ...extensions,
languageCompartment.of([]),
historyCompartment.of(history()),
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
@@ -36,8 +45,8 @@ export default class CodeMirror extends EditorView {
...defaultKeymap,
...historyKeymap,
indentWithTab
- ]),
- ];
+ ])
+ ]
if (Array.isArray(config.extensions)) {
extensions = [...extensions, ...config.extensions];
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 77578920c5..2ad7918e72 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1187,6 +1187,9 @@ importers:
'@codemirror/view':
specifier: 6.36.7
version: 6.36.7
+ '@replit/codemirror-vim':
+ specifier: 6.3.0
+ version: 6.3.0(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])
'@ssddanbrown/codemirror-lang-smarty':
specifier: 1.0.0
version: 1.0.0
@@ -4292,6 +4295,15 @@ packages:
'@radix-ui/[email protected]':
resolution: {integrity: sha512-A9+lCBZoaMJlVKcRBz2YByCG+Cp2t6nAnMnNba+XiWxnj6r4JUFqfsgwocMBZU9LPtdxC6wB56ySYpc7LQIoJg==}
+ '@replit/[email protected]':
+ resolution: {integrity: sha512-aTx931ULAMuJx6xLf7KQDOL7CxD+Sa05FktTDrtLaSy53uj01ll3Zf17JdKsriER248oS55GBzg0CfCTjEneAQ==}
+ peerDependencies:
+ '@codemirror/commands': 6.x.x
+ '@codemirror/language': 6.x.x
+ '@codemirror/search': 6.x.x
+ '@codemirror/state': 6.x.x
+ '@codemirror/view': 6.x.x
+
'@rollup/[email protected]':
resolution: {integrity: sha512-ZEZWTK5n6Qde0to4vS9Mr5x/0UZoqCxPVR9KRUjU4kA2sO7GEUn1fop0DAwpO6z0Nw/kJON9bDmSxdWxO/TT1A==}
engines: {node: '>=14.0.0'}
@@ -19393,6 +19405,14 @@ snapshots:
'@radix-ui/[email protected]': {}
+ '@replit/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])':
+ dependencies:
+ '@codemirror/commands': 6.8.1
+ '@codemirror/language': 6.11.0
+ '@codemirror/search': 6.5.10
+ '@codemirror/state': 6.5.2
+ '@codemirror/view': 6.36.7
+
dependencies:
'@rollup/pluginutils': 5.1.4([email protected])