feat(editor): Allow tab to accept completion (#5855)

 Allow `tab` to accept completion
This commit is contained in:
Iván Ovejero 2023-03-31 11:23:16 +02:00 committed by GitHub
parent f7f9d915b1
commit 1b8c35ab87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -16,7 +16,7 @@ import { n8nLang } from '@/plugins/codemirror/n8nLang';
import { highlighter } from '@/plugins/codemirror/resolvableHighlighter'; import { highlighter } from '@/plugins/codemirror/resolvableHighlighter';
import { inputTheme } from './theme'; import { inputTheme } from './theme';
import { forceParse } from '@/utils/forceParse'; import { forceParse } from '@/utils/forceParse';
import { autocompletion } from '@codemirror/autocomplete'; import { acceptCompletion, autocompletion } from '@codemirror/autocomplete';
import type { IVariableItemSelected } from '@/Interface'; import type { IVariableItemSelected } from '@/Interface';
@ -44,6 +44,7 @@ export default mixins(expressionManager, completionManager, workflowHelpers).ext
autocompletion(), autocompletion(),
Prec.highest( Prec.highest(
keymap.of([ keymap.of([
{ key: 'Tab', run: acceptCompletion },
{ {
any: (_: EditorView, event: KeyboardEvent) => { any: (_: EditorView, event: KeyboardEvent) => {
if (event.key === 'Escape') { if (event.key === 'Escape') {

View file

@ -8,7 +8,7 @@ import { mapStores } from 'pinia';
import { EditorView, keymap } from '@codemirror/view'; import { EditorView, keymap } from '@codemirror/view';
import { EditorState, Prec } from '@codemirror/state'; import { EditorState, Prec } from '@codemirror/state';
import { history, redo } from '@codemirror/commands'; import { history, redo } from '@codemirror/commands';
import { autocompletion, completionStatus } from '@codemirror/autocomplete'; import { acceptCompletion, autocompletion, completionStatus } from '@codemirror/autocomplete';
import { useNDVStore } from '@/stores/ndv'; import { useNDVStore } from '@/stores/ndv';
import { workflowHelpers } from '@/mixins/workflowHelpers'; import { workflowHelpers } from '@/mixins/workflowHelpers';
@ -78,6 +78,7 @@ export default mixins(completionManager, expressionManager, workflowHelpers).ext
inputTheme({ isSingleLine: this.isSingleLine }), inputTheme({ isSingleLine: this.isSingleLine }),
Prec.highest( Prec.highest(
keymap.of([ keymap.of([
{ key: 'Tab', run: acceptCompletion },
{ {
any(view: EditorView, event: KeyboardEvent) { any(view: EditorView, event: KeyboardEvent) {
if (event.key === 'Escape' && completionStatus(view.state) !== null) { if (event.key === 'Escape' && completionStatus(view.state) !== null) {