diff options
author | Kristóf Marussy <kristof@marussy.com> | 2024-04-27 00:51:23 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2024-04-27 00:51:23 +0200 |
commit | 28a20227c27065c7a85c941064456533b1130fee (patch) | |
tree | bb04ada61e965eca7fb2a8759a9356dd8ffc621a | |
parent | fix(reasoning): default assertions for containment references (diff) | |
download | refinery-28a20227c27065c7a85c941064456533b1130fee.tar.gz refinery-28a20227c27065c7a85c941064456533b1130fee.tar.zst refinery-28a20227c27065c7a85c941064456533b1130fee.zip |
refactor(frontend): improve key bindings
* Accept completions with both Enter or Tab.
* Ctrl-d duplicates current line (use Ctrl-Shift-d to select next occurrence).
* Suppress browser save dialog on Ctrl-s even if there are no changes.
-rw-r--r-- | subprojects/frontend/src/editor/createEditorState.ts | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/subprojects/frontend/src/editor/createEditorState.ts b/subprojects/frontend/src/editor/createEditorState.ts index 9b29228f..292505e4 100644 --- a/subprojects/frontend/src/editor/createEditorState.ts +++ b/subprojects/frontend/src/editor/createEditorState.ts | |||
@@ -5,12 +5,14 @@ | |||
5 | */ | 5 | */ |
6 | 6 | ||
7 | import { | 7 | import { |
8 | acceptCompletion, | ||
9 | autocompletion, | ||
8 | closeBrackets, | 10 | closeBrackets, |
9 | closeBracketsKeymap, | 11 | closeBracketsKeymap, |
10 | autocompletion, | ||
11 | completionKeymap, | 12 | completionKeymap, |
12 | } from '@codemirror/autocomplete'; | 13 | } from '@codemirror/autocomplete'; |
13 | import { | 14 | import { |
15 | copyLineDown, | ||
14 | defaultKeymap, | 16 | defaultKeymap, |
15 | history, | 17 | history, |
16 | historyKeymap, | 18 | historyKeymap, |
@@ -25,7 +27,7 @@ import { | |||
25 | syntaxHighlighting, | 27 | syntaxHighlighting, |
26 | } from '@codemirror/language'; | 28 | } from '@codemirror/language'; |
27 | import { lintKeymap, lintGutter } from '@codemirror/lint'; | 29 | import { lintKeymap, lintGutter } from '@codemirror/lint'; |
28 | import { search, searchKeymap } from '@codemirror/search'; | 30 | import { search, searchKeymap, selectNextOccurrence } from '@codemirror/search'; |
29 | import { Compartment, EditorState, type Extension } from '@codemirror/state'; | 31 | import { Compartment, EditorState, type Extension } from '@codemirror/state'; |
30 | import { | 32 | import { |
31 | drawSelection, | 33 | drawSelection, |
@@ -109,13 +111,20 @@ export default function createEditorState( | |||
109 | }), | 111 | }), |
110 | keymap.of([ | 112 | keymap.of([ |
111 | { key: 'Mod-Shift-f', run: () => store.formatText() }, | 113 | { key: 'Mod-Shift-f', run: () => store.formatText() }, |
112 | { key: 'Ctrl-o', run: () => store.openFile() }, | 114 | { key: 'Mod-o', run: () => store.openFile() }, |
113 | { key: 'Ctrl-s', run: () => store.saveFile() }, | 115 | { |
114 | { key: 'Ctrl-Shift-s', run: () => store.saveFileAs() }, | 116 | key: 'Mod-s', |
117 | run: () => store.saveFile(), | ||
118 | shift: () => store.saveFileAs(), | ||
119 | preventDefault: true, | ||
120 | }, | ||
115 | ...closeBracketsKeymap, | 121 | ...closeBracketsKeymap, |
116 | ...completionKeymap, | 122 | ...completionKeymap, |
117 | ...foldKeymap, | 123 | ...foldKeymap, |
118 | ...historyKeymap, | 124 | ...historyKeymap, |
125 | // Enable accepting completions with tab, overrides `Tab` from | ||
126 | // `indentWithTab` if there is an active completion. | ||
127 | { key: 'Tab', run: acceptCompletion }, | ||
119 | indentWithTab, | 128 | indentWithTab, |
120 | // Override keys in `lintKeymap` to go through the `EditorStore`. | 129 | // Override keys in `lintKeymap` to go through the `EditorStore`. |
121 | { key: 'Mod-Shift-m', run: () => store.lintPanel.open() }, | 130 | { key: 'Mod-Shift-m', run: () => store.lintPanel.open() }, |
@@ -131,6 +140,13 @@ export default function createEditorState( | |||
131 | run: () => store.searchPanel.close(), | 140 | run: () => store.searchPanel.close(), |
132 | scope: 'editor search-panel', | 141 | scope: 'editor search-panel', |
133 | }, | 142 | }, |
143 | // Override `Mod-d` from `searchKeymap`. | ||
144 | { | ||
145 | key: 'Mod-d', | ||
146 | run: copyLineDown, | ||
147 | shift: selectNextOccurrence, | ||
148 | preventDefault: true, | ||
149 | }, | ||
134 | ...searchKeymap, | 150 | ...searchKeymap, |
135 | ...defaultKeymap, | 151 | ...defaultKeymap, |
136 | ]), | 152 | ]), |