fix: ALT+F5 not falling back to statement under cursor#10173
Open
kundansable wants to merge 1 commit into
Open
fix: ALT+F5 not falling back to statement under cursor#10173kundansable wants to merge 1 commit into
kundansable wants to merge 1 commit into
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughQuery execution and cursor warning handling now treat whitespace-only selections as absent and read cursor queries from the editor’s main selection head. ChangesQuery selection handling
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #10109 —
ALT+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()computesquery = getSelection()and only falls back togetQueryAt(cursor)whenqueryis 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 thegetQueryAtfallback entirely, soALT+F5ends up trying to execute whitespace and silently does nothing. The same stale check exists incheckUnderlineQueryCursorWarning(). There is also a latent, previously-masked bug:state.selection.headis referenced whereEditorSelectionhas no such property — the correct field isstate.selection.main.head.Fix
Treat a whitespace-only
getSelection()result as empty (if (!query?.trim()) query = '';) before the fallback check, in bothtriggerExecution()andcheckUnderlineQueryCursorWarning(), 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 thestate.selection.head→state.selection.main.headreference.Test Steps
select 2(no text highlighted).ALT+F5.select 2executes and returns its result — not both statements, not nothing.select 1and repeat — confirmselect 1executes.select 1(a real selection) and pressF5/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).Summary by CodeRabbit