From 8edaba015960fd3cb9de401d96e90c48c96bc267 Mon Sep 17 00:00:00 2001 From: Elias Meire Date: Fri, 8 Nov 2024 12:38:20 +0100 Subject: [PATCH] Do not show hover tooltip when autocomplete is active --- .../codemirror/tooltips/InfoBoxTooltip.ts | 3 +++ .../codemirror/tooltips/infoBoxTooltip.test.ts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/packages/editor-ui/src/plugins/codemirror/tooltips/InfoBoxTooltip.ts b/packages/editor-ui/src/plugins/codemirror/tooltips/InfoBoxTooltip.ts index db76510f7b..8b9c992fad 100644 --- a/packages/editor-ui/src/plugins/codemirror/tooltips/InfoBoxTooltip.ts +++ b/packages/editor-ui/src/plugins/codemirror/tooltips/InfoBoxTooltip.ts @@ -242,6 +242,9 @@ export const hoverTooltipSource = (view: EditorView, pos: number) => { const state = view.state.field(cursorInfoBoxTooltip, false); const cursorTooltipOpen = !!state?.tooltip; + // Don't show hover tooltips when autocomplete is active + if (completionStatus(view.state) === 'active') return null; + const jsNodeResult = getJsNodeAtPosition(view.state, pos); if (!jsNodeResult) { diff --git a/packages/editor-ui/src/plugins/codemirror/tooltips/infoBoxTooltip.test.ts b/packages/editor-ui/src/plugins/codemirror/tooltips/infoBoxTooltip.test.ts index d248cb1ac4..7c4f7f499b 100644 --- a/packages/editor-ui/src/plugins/codemirror/tooltips/infoBoxTooltip.test.ts +++ b/packages/editor-ui/src/plugins/codemirror/tooltips/infoBoxTooltip.test.ts @@ -6,6 +6,16 @@ import { n8nLang } from '@/plugins/codemirror/n8nLang'; import { hoverTooltipSource, infoBoxTooltips } from './InfoBoxTooltip'; import * as utils from '@/plugins/codemirror/completions/utils'; import * as workflowHelpers from '@/composables/useWorkflowHelpers'; +import { completionStatus } from '@codemirror/autocomplete'; + +vi.mock('@codemirror/autocomplete', async (importOriginal) => { + const actual = await importOriginal<{}>(); + + return { + ...actual, + completionStatus: vi.fn(() => null), + }; +}); describe('Infobox tooltips', () => { beforeEach(() => { @@ -99,6 +109,13 @@ describe('Infobox tooltips', () => { expect(tooltip).not.toBeNull(); expect(infoBoxHeader(tooltip?.view)).toHaveTextContent('includes(searchString, start?)'); }); + + test('should not show a tooltip when autocomplete is open', () => { + vi.spyOn(workflowHelpers, 'resolveParameter').mockReturnValue('foo'); + vi.mocked(completionStatus).mockReturnValue('active'); + const tooltip = hoverTooltip('{{ $json.str.includ|es() }}'); + expect(tooltip).toBeNull(); + }); }); });