Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(editor): Add sections to autocomplete dropdown #8720

Merged
merged 29 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cc050f0
Overhaul autocomplete styling
elsmr Feb 22, 2024
26aab04
Reuse keymap and autocompletion options across editors
elsmr Feb 22, 2024
b228f7a
Add .keys and .values extension, remove invalid native
elsmr Feb 22, 2024
2884503
Add sections to autocomplete dropdown
elsmr Feb 22, 2024
a73a2ae
Add test coverage for sections and recommended completions
elsmr Feb 22, 2024
34575a5
Add recommended completions for arrays,objects and dates
elsmr Feb 22, 2024
4f859ca
Enable closeOnBlur
elsmr Feb 22, 2024
3ed5fc4
Merge branch 'master' into node-1147-introduce-autocomplete-inner-sec…
elsmr Feb 22, 2024
a4009ed
Remove unused imports
elsmr Feb 22, 2024
e0d7474
Add label for isExecuted
elsmr Feb 23, 2024
8c9463a
Replace regex based parsing with codemirror javascript parser
elsmr Feb 23, 2024
9ac02f0
Add sections to Strings and Dates
elsmr Feb 26, 2024
8553c24
Fix sticky header styling in Chrome
elsmr Feb 26, 2024
a124929
Avoid highligher error breaking editor
elsmr Feb 26, 2024
6a21745
Improve autocomplete sections
elsmr Feb 26, 2024
2675c46
Fix completion tests
elsmr Feb 26, 2024
a400f27
Tweak autocomplete styling
elsmr Feb 26, 2024
a261383
Merge branch 'master' into node-1147-introduce-autocomplete-inner-sec…
elsmr Feb 27, 2024
dc3113f
Fix review feedback
elsmr Feb 27, 2024
2193c50
Fix review feedback
elsmr Feb 28, 2024
6e997d4
Remove unused import
elsmr Feb 28, 2024
85a0c2d
Autocomplete groups styling.
gandreini Mar 4, 2024
4c850fa
Improved autocomplete sections style for dark mode.
gandreini Mar 4, 2024
54c2cbd
Remove unused constant
elsmr Mar 5, 2024
0d4061b
Remove unused CSS variables
elsmr Mar 5, 2024
c6b9f90
Merge branch 'master' into node-1147-introduce-autocomplete-inner-sec…
elsmr Mar 6, 2024
eeae05e
Capture error in Sentry
elsmr Mar 6, 2024
5be8205
Fix e2e tests
elsmr Mar 6, 2024
546d88e
Merge branch 'master' into node-1147-introduce-autocomplete-inner-sec…
elsmr Mar 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/design-system/src/css/_tokens.dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
--color-sticky-background-7: var(--prim-gray-740);
--color-sticky-border-7: var(--prim-gray-670);

// Expressions
// Expressions and autocomplete
--color-valid-resolvable-foreground: var(--prim-color-alt-a-tint-300);
--color-valid-resolvable-background: var(--prim-color-alt-a-alpha-025);
--color-invalid-resolvable-foreground: var(--prim-color-alt-c-tint-250);
Expand All @@ -78,6 +78,8 @@
--color-pending-resolvable-background: var(--prim-gray-70-alpha-01);
--color-expression-editor-background: var(--prim-gray-800);
--color-expression-syntax-example: var(--prim-gray-670);
--color-autocomplete-item-selected: var(--prim-color-secondary-tint-200);
--color-autocomplete-section-header-border: var(--prim-gray-540);

// Code
--color-code-tags-string: var(--prim-color-alt-f-tint-150);
Expand Down
6 changes: 3 additions & 3 deletions packages/design-system/src/css/_tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
--color-sticky-background-7: var(--prim-gray-10);
--color-sticky-border-7: var(--prim-gray-120);

// Expressions
// Expressions and autocomplete
--color-valid-resolvable-foreground: var(--prim-color-alt-a);
--color-valid-resolvable-background: var(--prim-color-alt-a-tint-500);
--color-invalid-resolvable-foreground: var(--prim-color-alt-c);
Expand All @@ -111,6 +111,8 @@
--color-pending-resolvable-background: var(--prim-gray-40);
--color-expression-editor-background: var(--prim-gray-0);
--color-expression-syntax-example: var(--prim-gray-40);
--color-autocomplete-item-selected: var(--color-secondary);
--color-autocomplete-section-header-border: var(--color-foreground-light);

// Code
--color-code-tags-string: var(--prim-color-alt-f);
Expand Down Expand Up @@ -138,8 +140,6 @@
--color-code-gutterBackground: var(--prim-gray-0);
--color-code-gutterForeground: var(--prim-gray-320);
--color-code-tags-comment: var(--prim-gray-420);
--color-autocomplete-selected-background: var(--prim-color-alt-e);
--color-autocomplete-selected-font: var(--prim-gray-0);

// Variables
--color-variables-usage-font: var(--color-success);
Expand Down
61 changes: 10 additions & 51 deletions packages/editor-ui/src/components/CodeNodeEditor/baseExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,26 @@ import {
highlightSpecialChars,
keymap,
lineNumbers,
type KeyBinding,
} from '@codemirror/view';
import { bracketMatching, foldGutter, indentOnInput } from '@codemirror/language';
import { acceptCompletion, selectedCompletion } from '@codemirror/autocomplete';
import {
history,
indentLess,
indentMore,
insertNewlineAndIndent,
toggleComment,
redo,
deleteCharBackward,
undo,
} from '@codemirror/commands';
import { history, toggleComment, deleteCharBackward } from '@codemirror/commands';
import { lintGutter } from '@codemirror/lint';
import { type Extension, Prec } from '@codemirror/state';

import { codeInputHandler } from '@/plugins/codemirror/inputHandlers/code.inputHandler';
import {
autocompleteKeyMap,
enterKeyMap,
historyKeyMap,
tabKeyMap,
} from '@/plugins/codemirror/keymap';

export const readOnlyEditorExtensions: readonly Extension[] = [
lineNumbers(),
EditorView.lineWrapping,
highlightSpecialChars(),
];

export const tabKeyMap: KeyBinding[] = [
{
any(editor, event) {
if (event.key === 'Tab' || (event.key === 'Escape' && selectedCompletion(editor.state))) {
event.stopPropagation();
}

return false;
},
},
{
key: 'Tab',
run: (editor) => {
if (selectedCompletion(editor.state)) {
return acceptCompletion(editor);
}

return indentMore(editor);
},
},
{ key: 'Shift-Tab', run: indentLess },
];

export const enterKeyMap: KeyBinding[] = [
{
key: 'Enter',
run: (editor) => {
if (selectedCompletion(editor.state)) {
return acceptCompletion(editor);
}

return insertNewlineAndIndent(editor);
},
},
];

export const writableEditorExtensions: readonly Extension[] = [
history(),
lintGutter(),
Expand All @@ -79,11 +38,11 @@ export const writableEditorExtensions: readonly Extension[] = [
highlightActiveLineGutter(),
Prec.highest(
keymap.of([
...tabKeyMap,
...tabKeyMap(),
...enterKeyMap,
...autocompleteKeyMap,
...historyKeyMap,
{ key: 'Mod-/', run: toggleComment },
{ key: 'Mod-z', run: undo },
{ key: 'Mod-Shift-z', run: redo },
{ key: 'Backspace', run: deleteCharBackward, shift: deleteCharBackward },
]),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@
import { defineComponent } from 'vue';
import { EditorView, keymap } from '@codemirror/view';
import { EditorState, Prec } from '@codemirror/state';
import { history, redo, undo } from '@codemirror/commands';
import { history } from '@codemirror/commands';

import { expressionManager } from '@/mixins/expressionManager';
import { completionManager } from '@/mixins/completionManager';
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 { inputTheme } from './theme';
import { forceParse } from '@/utils/forceParse';
import { acceptCompletion, autocompletion } from '@codemirror/autocomplete';
import { completionStatus } from '@codemirror/autocomplete';

import type { IVariableItemSelected } from '@/Interface';
import {
autocompleteKeyMap,
enterKeyMap,
historyKeyMap,
tabKeyMap,
} from '@/plugins/codemirror/keymap';

export default defineComponent({
name: 'ExpressionEditorModalInput',
Expand All @@ -44,25 +50,26 @@ export default defineComponent({
mounted() {
const extensions = [
inputTheme(),
autocompletion(),
Prec.highest(
keymap.of([
{ key: 'Tab', run: acceptCompletion },
...tabKeyMap(),
...historyKeyMap,
...enterKeyMap,
...autocompleteKeyMap,
{
any: (_: EditorView, event: KeyboardEvent) => {
if (event.key === 'Escape') {
any: (view, event) => {
if (event.key === 'Escape' && completionStatus(view.state) === null) {
event.stopPropagation();
this.$emit('close');
}

return false;
},
},
{ key: 'Mod-z', run: undo },
{ key: 'Mod-Shift-z', run: redo },
]),
),
n8nLang(),
n8nAutocompletion(),
history(),
expressionInputHandler(),
EditorView.lineWrapping,
Expand All @@ -71,7 +78,11 @@ export default defineComponent({
EditorView.contentAttributes.of({ 'data-gramm': 'false' }), // disable grammarly
EditorView.domEventHandlers({ scroll: forceParse }),
EditorView.updateListener.of((viewUpdate) => {
if (!this.editor || !viewUpdate.docChanged) return;
if (!this.editor) return;

this.completionStatus = completionStatus(viewUpdate.view.state);

if (!viewUpdate.docChanged) return;

this.editorState = this.editor.state;

Expand Down
27 changes: 16 additions & 11 deletions packages/editor-ui/src/components/HtmlEditor/HtmlEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
</template>

<script lang="ts">
import { autocompletion } from '@codemirror/autocomplete';
import { history, redo, undo } from '@codemirror/commands';
import { history } from '@codemirror/commands';
import {
LanguageSupport,
bracketMatching,
Expand Down Expand Up @@ -39,11 +38,18 @@ import { expressionManager } from '@/mixins/expressionManager';
import { n8nCompletionSources } from '@/plugins/codemirror/completions/addCompletions';
import { expressionInputHandler } from '@/plugins/codemirror/inputHandlers/expression.inputHandler';
import { highlighter } from '@/plugins/codemirror/resolvableHighlighter';
import { enterKeyMap, tabKeyMap } from '../CodeNodeEditor/baseExtensions';
import { codeNodeEditorTheme } from '../CodeNodeEditor/theme';
import type { Range, Section } from './types';
import { nonTakenRanges } from './utils';
import { isEqual } from 'lodash-es';
import {
autocompleteKeyMap,
enterKeyMap,
historyKeyMap,
tabKeyMap,
} from '@/plugins/codemirror/keymap';
import { n8nAutocompletion } from '@/plugins/codemirror/n8nLang';
import { completionStatus } from '@codemirror/autocomplete';

export default defineComponent({
name: 'HtmlEditor',
Expand Down Expand Up @@ -105,17 +111,12 @@ export default defineComponent({

return [
bracketMatching(),
autocompletion(),
n8nAutocompletion(),
this.disableExpressionCompletions ? html() : htmlWithCompletions(),
autoCloseTags,
expressionInputHandler(),
Prec.highest(
keymap.of([
...tabKeyMap,
...enterKeyMap,
{ key: 'Mod-z', run: undo },
{ key: 'Mod-Shift-z', run: redo },
]),
keymap.of([...tabKeyMap(), ...enterKeyMap, ...historyKeyMap, ...autocompleteKeyMap]),
),
indentOnInput(),
codeNodeEditorTheme({
Expand All @@ -135,7 +136,11 @@ export default defineComponent({
EditorView.editable.of(!this.isReadOnly),
EditorState.readOnly.of(this.isReadOnly),
EditorView.updateListener.of((viewUpdate: 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();

Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down
19 changes: 12 additions & 7 deletions packages/editor-ui/src/components/JsEditor/JsEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
</template>

<script lang="ts">
import { autocompletion } from '@codemirror/autocomplete';
import { history, redo, toggleComment, undo } from '@codemirror/commands';
import { history, toggleComment } from '@codemirror/commands';
import { javascript } from '@codemirror/lang-javascript';
import { foldGutter, indentOnInput } from '@codemirror/language';
import { lintGutter } from '@codemirror/lint';
Expand All @@ -24,8 +23,14 @@ import {
} from '@codemirror/view';
import { defineComponent } from 'vue';

import { enterKeyMap, tabKeyMap } from '../CodeNodeEditor/baseExtensions';
import { codeNodeEditorTheme } from '../CodeNodeEditor/theme';
import {
autocompleteKeyMap,
enterKeyMap,
historyKeyMap,
tabKeyMap,
} from '@/plugins/codemirror/keymap';
import { n8nAutocompletion } from '@/plugins/codemirror/n8nLang';

export default defineComponent({
name: 'JsEditor',
Expand Down Expand Up @@ -77,15 +82,15 @@ export default defineComponent({
history(),
Prec.highest(
keymap.of([
...tabKeyMap,
...tabKeyMap(),
...enterKeyMap,
{ key: 'Mod-z', run: undo },
{ key: 'Mod-Shift-z', run: redo },
...historyKeyMap,
...autocompleteKeyMap,
{ key: 'Mod-/', run: toggleComment },
]),
),
lintGutter(),
autocompletion(),
n8nAutocompletion(),
indentOnInput(),
highlightActiveLine(),
highlightActiveLineGutter(),
Expand Down
Loading
Loading