From 28a20227c27065c7a85c941064456533b1130fee Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sat, 27 Apr 2024 00:51:23 +0200 Subject: 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. --- .../frontend/src/editor/createEditorState.ts | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'subprojects/frontend/src/editor/createEditorState.ts') 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 @@ */ import { + acceptCompletion, + autocompletion, closeBrackets, closeBracketsKeymap, - autocompletion, completionKeymap, } from '@codemirror/autocomplete'; import { + copyLineDown, defaultKeymap, history, historyKeymap, @@ -25,7 +27,7 @@ import { syntaxHighlighting, } from '@codemirror/language'; import { lintKeymap, lintGutter } from '@codemirror/lint'; -import { search, searchKeymap } from '@codemirror/search'; +import { search, searchKeymap, selectNextOccurrence } from '@codemirror/search'; import { Compartment, EditorState, type Extension } from '@codemirror/state'; import { drawSelection, @@ -109,13 +111,20 @@ export default function createEditorState( }), keymap.of([ { key: 'Mod-Shift-f', run: () => store.formatText() }, - { key: 'Ctrl-o', run: () => store.openFile() }, - { key: 'Ctrl-s', run: () => store.saveFile() }, - { key: 'Ctrl-Shift-s', run: () => store.saveFileAs() }, + { key: 'Mod-o', run: () => store.openFile() }, + { + key: 'Mod-s', + run: () => store.saveFile(), + shift: () => store.saveFileAs(), + preventDefault: true, + }, ...closeBracketsKeymap, ...completionKeymap, ...foldKeymap, ...historyKeymap, + // Enable accepting completions with tab, overrides `Tab` from + // `indentWithTab` if there is an active completion. + { key: 'Tab', run: acceptCompletion }, indentWithTab, // Override keys in `lintKeymap` to go through the `EditorStore`. { key: 'Mod-Shift-m', run: () => store.lintPanel.open() }, @@ -131,6 +140,13 @@ export default function createEditorState( run: () => store.searchPanel.close(), scope: 'editor search-panel', }, + // Override `Mod-d` from `searchKeymap`. + { + key: 'Mod-d', + run: copyLineDown, + shift: selectNextOccurrence, + preventDefault: true, + }, ...searchKeymap, ...defaultKeymap, ]), -- cgit v1.2.3-70-g09d2