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

triggerExecution() only fell back to getQueryAt(cursor) when
getSelection() was falsy. Since #7293/#8691 (non-continuous
highlighted-block support), getSelection() flattens and joins all
ranges, so multiple empty cursor ranges can produce a truthy but
whitespace-only string (e.g. "\n"), skipping the fallback entirely —
ALT+F5 silently tried to execute whitespace. Same stale check existed
in checkUnderlineQueryCursorWarning(). Also fixes a latent
state.selection.head reference (EditorSelection has no such
property; correct field is state.selection.main.head).

Treat a whitespace-only selection as empty before the fallback check
in both functions. Real highlighted selections always contain
non-whitespace, so #7293/#9570 behavior is unaffected.

Fixes #10109
This commit is contained in:
Kundan
2026-07-24 18:07:26 +05:30
committed by GitHub
parent 8812025a8a
commit aeef9c2d80
@@ -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 (<ConfirmExecuteQueryContent
closeModal={closeModal}