From 21221cec658056e8dd8ab6e68215dc639df0700a Mon Sep 17 00:00:00 2001 From: Kundan Sable Date: Wed, 22 Jul 2026 15:40:00 +0530 Subject: [PATCH] fix: ALT+F5 not falling back to statement under cursor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit triggerExecution() computes query = getSelection() and only falls back to getQueryAt(cursor) when that's falsy. Since #7293/#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 #9570/#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 #10109 --- .../static/js/components/sections/Query.jsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx b/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx index f6cffe3df7b..d2759ea51de 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx @@ -143,13 +143,23 @@ export default function Query({onTextSelect, setQtStatePartial}) { if(queryToolCtx.params.is_query_tool) { let external = null; let query = editor.current?.getSelection(); + /* getSelection() flattens all selection ranges joined by the line + * separator (to support running non-continuous highlighted blocks). + * When nothing is actually highlighted this can still yield a + * whitespace-only string (e.g. several empty cursors joined by + * newlines), which is truthy and would suppress the cursor / + * whole-editor fallbacks below - making ALT+F5 (Execute query) do + * nothing. Treat a whitespace-only selection as no selection. #10109 */ + if(!query?.trim()) { + query = ''; + } if(!_.isEmpty(macroSQL)) { const regex = /\$SELECTION\$/gi; query = macroSQL.replace(regex, query); external = true; } else if(executeCursor || explainObject) { /* Execute query at cursor position or explain query at cursor position */ - query = query || editor.current?.getQueryAt(editor.current?.state.selection.head).value || ''; + query = query || editor.current?.getQueryAt(editor.current?.state.selection.main.head).value || ''; } else { /* Normal execution */ query = query || editor.current?.getValue() || ''; @@ -443,7 +453,12 @@ export default function Query({onTextSelect, setQtStatePartial}) { const checkUnderlineQueryCursorWarning = () => { let query = editor.current?.getSelection(); - query = query || editor.current?.getQueryAt(editor.current?.state.selection.head).value || ''; + /* Ignore a whitespace-only selection so the warning previews the query + * under the cursor, matching triggerExecution. #10109 */ + if(!query?.trim()) { + query = ''; + } + query = query || editor.current?.getQueryAt(editor.current?.state.selection.main.head).value || ''; query && queryToolCtx.modal.showModal(gettext('Execute query'), (closeModal) =>{ return (