Skip to content

Query editor mouse events swallowed by autocomplete panel background #1831

Description

@yankewei

What happened?

In the SQL query editor, the mouse frequently becomes unresponsive after the autocomplete panel appears. Clicks that should place the cursor, select text, or open the context menu (copy/paste) are lost when they land on the autocomplete panel's background, padding, or rounded corners instead of reaching the editor.

This appears to be a remaining edge case after the #1815 fix, which added a local mouse monitor that only dismisses the panel when the click is outside the panel's frame. Clicks that fall inside the panel frame but outside the actual suggestion items are still routed to the panel window and swallowed.

Steps to reproduce

  1. Open a query tab and start typing SQL to trigger autocomplete (e.g. type SEL or SELECT * FROM ).
  2. Wait for the autocomplete panel to appear.
  3. Click on the panel's background, vertical padding, or rounded corner area — not on a suggestion row.
  4. Observe that the panel does not dismiss and the editor does not receive the click.

Expected behavior

Clicking any non-interactive area of the autocomplete panel should dismiss it and return mouse control to the editor.

Root cause

SuggestionController shows the autocomplete list in a child NSPanel ordered above the editor window (SuggestionPanel, level .popUpMenu). The local mouse monitor added in #1815 closes the panel only when event.window !== panel. When the click lies inside the panel frame, AppKit routes the event to the panel window; the monitor returns the event unchanged, and the panel's transparent background swallows it. The editor text view never sees the click.

Suggested fix

Add a background tap gesture to the SwiftUI content so that taps on non-interactive areas of the panel call back to the controller and close the panel.

Files to change

  1. LocalPackages/CodeEditSourceEditor/Sources/CodeEditSourceEditor/CodeSuggestion/Model/SuggestionViewModel.swift

    • Add var onBackgroundTap: (() -> Void)?.
  2. LocalPackages/CodeEditSourceEditor/Sources/CodeEditSourceEditor/CodeSuggestion/Window/SuggestionController.swift

    • In init(), set model.onBackgroundTap = { [weak self] in self?.close() }.
  3. LocalPackages/CodeEditSourceEditor/Sources/CodeEditSourceEditor/CodeSuggestion/View/SuggestionContentView.swift

    • Wrap the .background(Color(nsColor: model.themeBackground)) with .contentShape(Rectangle()).onTapGesture { model.onBackgroundTap?() }.
  4. LocalPackages/CodeEditSourceEditor/Tests/CodeEditSourceEditorTests/CodeSuggestion/SuggestionApplyTests.swift

    • Add a test that calling model.onBackgroundTap?() clears the controller's model state.
  5. CHANGELOG.md

    • Add a note under [Unreleased] > Fixed.

Notes

  • This keeps list-row selection intact because row-level .onTapGesture modifiers take precedence over the parent background gesture.
  • This fix dismisses the panel on background clicks; placing the cursor at the clicked location will require a second click, which matches the standard autocomplete UX and the intent of Fix reported data grid, editor, and filter UX issues #1815.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions