diff --git a/cypress/e2e/29-sql-editor.cy.ts b/cypress/e2e/29-sql-editor.cy.ts index d8e6aed9b..86299d5f6 100644 --- a/cypress/e2e/29-sql-editor.cy.ts +++ b/cypress/e2e/29-sql-editor.cy.ts @@ -27,6 +27,26 @@ describe('SQL editors', () => { ndv.getters.sqlEditorContainer().should('contain', 'SELECT * FROM `testTable` LIMIT 10'); }); + it('should update expression output dropdown as the query is edited', () => { + workflowPage.actions.addInitialNodeToCanvas('MySQL', { + action: 'Execute a SQL query', + }); + ndv.actions.close(); + + workflowPage.actions.openNode('When clicking "Test workflow"'); + ndv.actions.setPinnedData([{ table: 'test_table' }]); + ndv.actions.close(); + + workflowPage.actions.openNode('MySQL'); + ndv.getters + .sqlEditorContainer() + .find('.cm-content') + .type('SELECT * FROM {{ $json.table }}', { parseSpecialCharSequences: false }); + workflowPage.getters + .inlineExpressionEditorOutput() + .should('have.text', 'SELECT * FROM test_table'); + }); + it('should not push NDV header out with a lot of code in Postgres editor', () => { workflowPage.actions.addInitialNodeToCanvas('Postgres', { action: 'Execute a SQL query', diff --git a/packages/editor-ui/src/components/HtmlEditor/HtmlEditor.vue b/packages/editor-ui/src/components/HtmlEditor/HtmlEditor.vue index 5aba6b063..01d4ea5a5 100644 --- a/packages/editor-ui/src/components/HtmlEditor/HtmlEditor.vue +++ b/packages/editor-ui/src/components/HtmlEditor/HtmlEditor.vue @@ -43,6 +43,7 @@ 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'; export default defineComponent({ name: 'HtmlEditor', @@ -79,6 +80,16 @@ export default defineComponent({ editorState: null as EditorState | null, }; }, + watch: { + displayableSegments(segments, newSegments) { + if (isEqual(segments, newSegments)) return; + + highlighter.removeColor(this.editor, this.plaintextSegments); + highlighter.addColor(this.editor, this.resolvableSegments); + + this.$emit('update:modelValue', this.editor?.state.doc.toString()); + }, + }, computed: { doc(): string { return this.editor.state.doc.toString(); @@ -124,13 +135,10 @@ export default defineComponent({ EditorView.editable.of(!this.isReadOnly), EditorState.readOnly.of(this.isReadOnly), EditorView.updateListener.of((viewUpdate: ViewUpdate) => { - if (!viewUpdate.docChanged) return; + if (!this.editor || !viewUpdate.docChanged) return; - this.getHighlighter()?.removeColor(this.editor, this.htmlSegments); - this.getHighlighter()?.addColor(this.editor, this.resolvableSegments); - - // eslint-disable-next-line @typescript-eslint/no-base-to-string - this.$emit('update:modelValue', this.editor?.state.doc.toString()); + // Force segments value update by keeping track of editor state + this.editorState = this.editor.state; }), ]; }, diff --git a/packages/editor-ui/src/components/SqlEditor/SqlEditor.vue b/packages/editor-ui/src/components/SqlEditor/SqlEditor.vue index fd33c1ea0..087f85374 100644 --- a/packages/editor-ui/src/components/SqlEditor/SqlEditor.vue +++ b/packages/editor-ui/src/components/SqlEditor/SqlEditor.vue @@ -1,6 +1,6 @@