aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2024-04-27 00:51:23 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2024-04-27 00:51:23 +0200
commit28a20227c27065c7a85c941064456533b1130fee (patch)
treebb04ada61e965eca7fb2a8759a9356dd8ffc621a /subprojects/frontend
parentfix(reasoning): default assertions for containment references (diff)
downloadrefinery-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.
Diffstat (limited to 'subprojects/frontend')
-rw-r--r--subprojects/frontend/src/editor/createEditorState.ts26
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
7import { 7import {
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';
13import { 14import {
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';
27import { lintKeymap, lintGutter } from '@codemirror/lint'; 29import { lintKeymap, lintGutter } from '@codemirror/lint';
28import { search, searchKeymap } from '@codemirror/search'; 30import { search, searchKeymap, selectNextOccurrence } from '@codemirror/search';
29import { Compartment, EditorState, type Extension } from '@codemirror/state'; 31import { Compartment, EditorState, type Extension } from '@codemirror/state';
30import { 32import {
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 ]),