Skip to content

AI Assistant 'Insert at Cursor' does not insert the SQL into the query editor #10690

Closed

Description

@dpage

Describe the bug

When the AI Assistant returns a SQL block, clicking "Insert at Cursor" switches to the Query tab but does not insert the SQL. "Replace Query" works correctly.

To Reproduce

  1. Open a Query Tool with an AI provider configured.
  2. Ask the AI Assistant for a query.
  3. Click "Insert at Cursor" on the returned SQL block: the Query tab is focused, but the editor content is unchanged.

Expected behavior

The SQL is inserted at the cursor position in the query editor.

Cause

The NLQ_INSERT_SQL listener at web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx:237-242 calls editor.current?.replaceRange(sql, cursorPos), which is a CodeMirror 5 API. The editor is now a CustomEditorView (CodeMirror 6, web/pgadmin/static/js/components/ReactCodeMirror/CustomEditorView.js), which has no replaceRange method, so the call throws a TypeError and nothing is inserted. The FOCUS_PANEL event is fired separately by NLQChatPanel.jsx, which is why the tab still switches.

Using the existing editor.current?.replaceSelection(sql) (which inserts at the cursor, or replaces any selected text) should fix it.

Desktop

  • pgAdmin version: 9.19 (release candidate builds)

Activity

  1. dpage commented on Nov 5, 2026

    @dpage
    ContributorAuthor

    Fixed in 5c83983 (#10692).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions