feat(editor): Add sections to autocomplete dropdown (#8720)
Co-authored-by: Giulio Andreini <andreini@netseven.it>
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { acceptCompletion, autocompletion, completionStatus } from '@codemirror/autocomplete';
|
||||
import { history, redo, undo } from '@codemirror/commands';
|
||||
import { history } from '@codemirror/commands';
|
||||
import { Compartment, EditorState, Prec } from '@codemirror/state';
|
||||
import { EditorView, keymap } from '@codemirror/view';
|
||||
import type { PropType } from 'vue';
|
||||
@@ -13,11 +12,18 @@ import { defineComponent } from 'vue';
|
||||
import { completionManager } from '@/mixins/completionManager';
|
||||
import { expressionManager } from '@/mixins/expressionManager';
|
||||
import { expressionInputHandler } from '@/plugins/codemirror/inputHandlers/expression.inputHandler';
|
||||
import { n8nLang } from '@/plugins/codemirror/n8nLang';
|
||||
import { n8nAutocompletion, n8nLang } from '@/plugins/codemirror/n8nLang';
|
||||
import { highlighter } from '@/plugins/codemirror/resolvableHighlighter';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import type { IDataObject } from 'n8n-workflow';
|
||||
import { inputTheme } from './theme';
|
||||
import {
|
||||
autocompleteKeyMap,
|
||||
enterKeyMap,
|
||||
historyKeyMap,
|
||||
tabKeyMap,
|
||||
} from '@/plugins/codemirror/keymap';
|
||||
import { completionStatus } from '@codemirror/autocomplete';
|
||||
|
||||
const editableConf = new Compartment();
|
||||
|
||||
@@ -81,25 +87,12 @@ export default defineComponent({
|
||||
},
|
||||
mounted() {
|
||||
const extensions = [
|
||||
n8nLang(),
|
||||
inputTheme({ rows: this.rows }),
|
||||
Prec.highest(
|
||||
keymap.of([
|
||||
{ key: 'Tab', run: acceptCompletion },
|
||||
{
|
||||
any(view: EditorView, event: KeyboardEvent) {
|
||||
if (event.key === 'Escape' && completionStatus(view.state) !== null) {
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
},
|
||||
{ key: 'Mod-z', run: undo },
|
||||
{ key: 'Mod-Shift-z', run: redo },
|
||||
]),
|
||||
keymap.of([...tabKeyMap(true), ...enterKeyMap, ...autocompleteKeyMap, ...historyKeyMap]),
|
||||
),
|
||||
autocompletion(),
|
||||
n8nLang(),
|
||||
n8nAutocompletion(),
|
||||
inputTheme({ rows: this.rows }),
|
||||
history(),
|
||||
expressionInputHandler(),
|
||||
EditorView.lineWrapping,
|
||||
@@ -111,7 +104,11 @@ export default defineComponent({
|
||||
},
|
||||
}),
|
||||
EditorView.updateListener.of((viewUpdate) => {
|
||||
if (!this.editor || !viewUpdate.docChanged) return;
|
||||
if (!this.editor) return;
|
||||
|
||||
this.completionStatus = completionStatus(viewUpdate.view.state);
|
||||
|
||||
if (!viewUpdate.docChanged) return;
|
||||
|
||||
// Force segments value update by keeping track of editor state
|
||||
this.editorState = this.editor.state;
|
||||
|
||||
Reference in New Issue
Block a user