mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-31 20:22:27 +08:00
chore(code): reintroduce vim keybindings
This commit is contained in:
parent
e5fad63403
commit
9b958fc659
@ -45,13 +45,13 @@ export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget {
|
|||||||
getExtraOpts(): Partial<EditorConfig> {
|
getExtraOpts(): Partial<EditorConfig> {
|
||||||
return {
|
return {
|
||||||
placeholder: t("editable_code.placeholder"),
|
placeholder: t("editable_code.placeholder"),
|
||||||
|
vimKeybindings: options.is("vimKeymapEnabled"),
|
||||||
onContentChanged: () => this.spacedUpdate.scheduleUpdate()
|
onContentChanged: () => this.spacedUpdate.scheduleUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// getExtraOpts(): Partial<CodeMirrorOpts> {
|
// getExtraOpts(): Partial<CodeMirrorOpts> {
|
||||||
// return {
|
// return {
|
||||||
// keyMap: options.is("vimKeymapEnabled") ? "vim" : "default",
|
|
||||||
// lint: true,
|
// lint: true,
|
||||||
// gutters: ["CodeMirror-lint-markers"],
|
// gutters: ["CodeMirror-lint-markers"],
|
||||||
// tabindex: 300,
|
// tabindex: 300,
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
"@codemirror/legacy-modes": "6.5.1",
|
"@codemirror/legacy-modes": "6.5.1",
|
||||||
"@codemirror/search": "6.5.10",
|
"@codemirror/search": "6.5.10",
|
||||||
"@codemirror/view": "6.36.7",
|
"@codemirror/view": "6.36.7",
|
||||||
|
"@replit/codemirror-vim": "6.3.0",
|
||||||
"@ssddanbrown/codemirror-lang-smarty": "1.0.0",
|
"@ssddanbrown/codemirror-lang-smarty": "1.0.0",
|
||||||
"@ssddanbrown/codemirror-lang-twig": "1.0.0",
|
"@ssddanbrown/codemirror-lang-twig": "1.0.0",
|
||||||
"codemirror-lang-hcl": "0.1.0",
|
"codemirror-lang-hcl": "0.1.0",
|
||||||
|
@ -3,6 +3,7 @@ import { EditorView, highlightActiveLine, keymap, lineNumbers, placeholder, View
|
|||||||
import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting, indentUnit, bracketMatching } from "@codemirror/language";
|
import { defaultHighlightStyle, StreamLanguage, syntaxHighlighting, indentUnit, bracketMatching } from "@codemirror/language";
|
||||||
import { Compartment, type Extension } from "@codemirror/state";
|
import { Compartment, type Extension } from "@codemirror/state";
|
||||||
import { highlightSelectionMatches } from "@codemirror/search";
|
import { highlightSelectionMatches } from "@codemirror/search";
|
||||||
|
import { vim } from "@replit/codemirror-vim";
|
||||||
import byMimeType from "./syntax_highlighting.js";
|
import byMimeType from "./syntax_highlighting.js";
|
||||||
|
|
||||||
type ContentChangedListener = () => void;
|
type ContentChangedListener = () => void;
|
||||||
@ -10,6 +11,7 @@ type ContentChangedListener = () => void;
|
|||||||
export interface EditorConfig extends EditorViewConfig {
|
export interface EditorConfig extends EditorViewConfig {
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
lineWrapping?: boolean;
|
lineWrapping?: boolean;
|
||||||
|
vimKeybindings?: boolean;
|
||||||
onContentChanged?: ContentChangedListener;
|
onContentChanged?: ContentChangedListener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +25,14 @@ export default class CodeMirror extends EditorView {
|
|||||||
const languageCompartment = new Compartment();
|
const languageCompartment = new Compartment();
|
||||||
const historyCompartment = new Compartment();
|
const historyCompartment = new Compartment();
|
||||||
|
|
||||||
let extensions = [
|
let extensions: Extension[] = [];
|
||||||
|
|
||||||
|
if (config.vimKeybindings) {
|
||||||
|
extensions.push(vim());
|
||||||
|
}
|
||||||
|
|
||||||
|
extensions = [
|
||||||
|
...extensions,
|
||||||
languageCompartment.of([]),
|
languageCompartment.of([]),
|
||||||
historyCompartment.of(history()),
|
historyCompartment.of(history()),
|
||||||
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
syntaxHighlighting(defaultHighlightStyle, { fallback: true }),
|
||||||
@ -36,8 +45,8 @@ export default class CodeMirror extends EditorView {
|
|||||||
...defaultKeymap,
|
...defaultKeymap,
|
||||||
...historyKeymap,
|
...historyKeymap,
|
||||||
indentWithTab
|
indentWithTab
|
||||||
]),
|
])
|
||||||
];
|
]
|
||||||
|
|
||||||
if (Array.isArray(config.extensions)) {
|
if (Array.isArray(config.extensions)) {
|
||||||
extensions = [...extensions, ...config.extensions];
|
extensions = [...extensions, ...config.extensions];
|
||||||
|
20
pnpm-lock.yaml
generated
20
pnpm-lock.yaml
generated
@ -1187,6 +1187,9 @@ importers:
|
|||||||
'@codemirror/view':
|
'@codemirror/view':
|
||||||
specifier: 6.36.7
|
specifier: 6.36.7
|
||||||
version: 6.36.7
|
version: 6.36.7
|
||||||
|
'@replit/codemirror-vim':
|
||||||
|
specifier: 6.3.0
|
||||||
|
version: 6.3.0(@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)
|
||||||
'@ssddanbrown/codemirror-lang-smarty':
|
'@ssddanbrown/codemirror-lang-smarty':
|
||||||
specifier: 1.0.0
|
specifier: 1.0.0
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
@ -4292,6 +4295,15 @@ packages:
|
|||||||
'@radix-ui/rect@1.1.0':
|
'@radix-ui/rect@1.1.0':
|
||||||
resolution: {integrity: sha512-A9+lCBZoaMJlVKcRBz2YByCG+Cp2t6nAnMnNba+XiWxnj6r4JUFqfsgwocMBZU9LPtdxC6wB56ySYpc7LQIoJg==}
|
resolution: {integrity: sha512-A9+lCBZoaMJlVKcRBz2YByCG+Cp2t6nAnMnNba+XiWxnj6r4JUFqfsgwocMBZU9LPtdxC6wB56ySYpc7LQIoJg==}
|
||||||
|
|
||||||
|
'@replit/codemirror-vim@6.3.0':
|
||||||
|
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/plugin-commonjs@25.0.8':
|
'@rollup/plugin-commonjs@25.0.8':
|
||||||
resolution: {integrity: sha512-ZEZWTK5n6Qde0to4vS9Mr5x/0UZoqCxPVR9KRUjU4kA2sO7GEUn1fop0DAwpO6z0Nw/kJON9bDmSxdWxO/TT1A==}
|
resolution: {integrity: sha512-ZEZWTK5n6Qde0to4vS9Mr5x/0UZoqCxPVR9KRUjU4kA2sO7GEUn1fop0DAwpO6z0Nw/kJON9bDmSxdWxO/TT1A==}
|
||||||
engines: {node: '>=14.0.0'}
|
engines: {node: '>=14.0.0'}
|
||||||
@ -19393,6 +19405,14 @@ snapshots:
|
|||||||
|
|
||||||
'@radix-ui/rect@1.1.0': {}
|
'@radix-ui/rect@1.1.0': {}
|
||||||
|
|
||||||
|
'@replit/codemirror-vim@6.3.0(@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:
|
||||||
|
'@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
|
||||||
|
|
||||||
'@rollup/plugin-commonjs@25.0.8(rollup@4.40.0)':
|
'@rollup/plugin-commonjs@25.0.8(rollup@4.40.0)':
|
||||||
dependencies:
|
dependencies:
|
||||||
'@rollup/pluginutils': 5.1.4(rollup@4.40.0)
|
'@rollup/pluginutils': 5.1.4(rollup@4.40.0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user