Skip to content

fix: ALT+F5 not falling back to statement under cursor#10173

Open
kundansable wants to merge 1 commit into
pgadmin-org:masterfrom
kundansable:fix-10109-altf5-cursor-query
Open

fix: ALT+F5 not falling back to statement under cursor#10173
kundansable wants to merge 1 commit into
pgadmin-org:masterfrom
kundansable:fix-10109-altf5-cursor-query

Conversation

@kundansable

@kundansable kundansable commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #10109ALT+F5 ("Execute query at cursor") does nothing when the cursor is on/near a statement that isn't highlighted, in a Query Tool tab with multiple statements separated by blank lines.

Root Cause

triggerExecution() computes query = getSelection() and only falls back to getQueryAt(cursor) when query is falsy. Since the fix for #7293/#8691 (support running non-continuous highlighted blocks), getSelection() flattens all selection ranges and joins them — so even with no real text highlighted, multiple empty cursor ranges can produce a truthy but whitespace-only string (e.g. "\n"). That truthy value skips the getQueryAt fallback entirely, so ALT+F5 ends up trying to execute whitespace and silently does nothing. The same stale check exists in checkUnderlineQueryCursorWarning(). There is also a latent, previously-masked bug: state.selection.head is referenced where EditorSelection has no such property — the correct field is state.selection.main.head.

Fix

Treat a whitespace-only getSelection() result as empty (if (!query?.trim()) query = '';) before the fallback check, in both triggerExecution() and checkUnderlineQueryCursorWarning(), so statement-at-cursor detection applies again whenever there's no genuine highlighted text. A real highlighted selection always contains non-whitespace, so the #7293/#9570 fix for running highlighted (including non-continuous) blocks is unaffected. Also corrects the state.selection.headstate.selection.main.head reference.

Test Steps

  1. Open the Query Tool and type:
    select 1
    
    select 2
  2. Click to place the cursor on/near select 2 (no text highlighted).
  3. Press ALT+F5.
  4. Expected: only select 2 executes and returns its result — not both statements, not nothing.
  5. Move the cursor to select 1 and repeat — confirm select 1 executes.
  6. Regression: highlight select 1 (a real selection) and press F5/ALT+F5 — confirm the highlighted statement still executes correctly (this must not regress ALT + F5 not running selected query #9570/Enhancement - Query Tool - Run SQL Code From non-contiguous highlighted code blocks #7293).
  7. Regression: highlight two non-continuous blocks (per Enhancement - Query Tool - Run SQL Code From non-contiguous highlighted code blocks #7293's original fix) and confirm both still execute together as before.

Summary by CodeRabbit

  • Bug Fixes
    • Improved query execution when editor selections contain only whitespace.
    • Prevented empty selection-based execution and cursor warning previews from running unnecessarily.
    • Improved cursor-based query detection for more reliable execution and warning behavior.

triggerExecution() computes query = getSelection() and only falls back
to getQueryAt(cursor) when that's falsy. Since pgadmin-org#7293/pgadmin-org#8691 changed
getSelection() to flatten all selection ranges (to support running
non-continuous highlighted blocks), a cursor with no real highlight
can still yield a truthy whitespace-only string (e.g. "\n") from
multiple empty ranges — which skips the cursor-statement fallback
entirely, so ALT+F5 silently executes whitespace and appears to do
nothing.

Treat a whitespace-only selection as empty before the fallback check,
in both triggerExecution() and checkUnderlineQueryCursorWarning(), so
statement-at-cursor detection applies again. A genuine highlighted
selection always contains non-whitespace, so pgadmin-org#9570/pgadmin-org#7293's fix (running
non-continuous highlighted blocks) is unaffected. Also fixes a latent
state.selection.head reference (EditorSelection has no such property;
the correct field is state.selection.main.head).

Fixes pgadmin-org#10109
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: af87c17e-e0d0-4da0-88d9-7332ea5401d4

📥 Commits

Reviewing files that changed from the base of the PR and between b15c745 and 21221ce.

📒 Files selected for processing (1)
  • web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx

Walkthrough

Query execution and cursor warning handling now treat whitespace-only selections as absent and read cursor queries from the editor’s main selection head.

Changes

Query selection handling

Layer / File(s) Summary
Normalize selections in execution and warning flows
web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx
triggerExecution and checkUnderlineQueryCursorWarning normalize whitespace-only selections and derive cursor queries from state.selection.main.head.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: dpage

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: ALT+F5 now falls back to the statement under the cursor.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kundansable kundansable self-assigned this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ALT + F5 not executing the unselected query the cursor is on or near

1 participant