Skip to content

feat(frontend): run statement at cursor on Cmd+Enter#464

Open
maximumbreak wants to merge 2 commits into
TabularisDB:mainfrom
maximumbreak:feature/run-statement-at-cursor
Open

feat(frontend): run statement at cursor on Cmd+Enter#464
maximumbreak wants to merge 2 commits into
TabularisDB:mainfrom
maximumbreak:feature/run-statement-at-cursor

Conversation

@maximumbreak

Copy link
Copy Markdown

Demo :

demo.mov

Summary

  • Cmd+Enter, Ctrl/Cmd+F5, and the Explain button now run/explain the SQL statement the cursor is currently inside when nothing is selected, instead of running the whole file or popping open a "pick a statement" modal — matching TablePlus/DataGrip behavior.
  • A subtle, theme-aware background highlight shows which statement is armed to run whenever there's no selection, and disappears the instant you make a selection.
  • Whole-file / multi-statement execution is still available by selecting all text first (Cmd+A) — no new UI needed for that.
  • Explaining a non-explainable statement (e.g. DDL) now shows a warning alert instead of silently doing something unexpected.
  • Fixes two related bugs surfaced by this workflow: running two different statements/tables back to back on the same tab could leave stale primary-key/column metadata from the previous statement applied to the new one (breaking inline cell editing with a misleading "column not editable" error naming the wrong table), and every pagination/refresh action (including the post-edit-save refresh) re-sent the entire editor buffer instead of the single statement that produced the current result — which Postgres rejects as "cannot insert multiple commands into a prepared statement" whenever the buffer holds more than one statement.

Details

  • Added findStatementAtOffset to sqlSplitter, resolving which statement a cursor offset falls inside using the splitter's existing (previously unused) per-statement range data. A cursor in the gap between two statements resolves to the preceding one; a cursor before the first statement does nothing.
  • handleRunButton/handleExplainButton in Editor.tsx now resolve the statement at the cursor via a shared helper instead of falling back to the whole file.
  • SqlEditorWrapper gained an opt-in dialect prop that drives the cursor-statement highlight decoration; other consumers of the component are unaffected since they don't pass it.
  • runQuery now tracks the exact statement it last ran per tab and a per-tab generation counter, so async responses (PK/column metadata fetch, the main query result) from a superseded run are dropped instead of clobbering a newer run's state, and pagination/refresh call sites now re-run "whatever's currently shown" instead of the raw multi-statement editor buffer.
  • QuerySelectionModal is left in the codebase but no longer reachable from the Run/Explain paths.

Test plan

  • pnpm test — 2797 tests pass, including new coverage for findStatementAtOffset (statement boundaries, gaps between statements, before/after the statement list, single-statement files)
  • pnpm typecheck / eslint clean
  • Manual pass in the running app: multi-statement tab, cursor in different statements with no selection (highlight + Cmd+Enter/F5/Explain all target the right one), select-all still runs everything, editing a cell after running a single statement out of a multi-statement tab, paging through results from that same scenario, and saving an edit — all previously reproduced the "multiple commands in a prepared statement" error and now work correctly

Let me know if you'd like it trimmed down or adjusted before you post it.

Cmd+Enter, Ctrl/Cmd+F5, and Explain now run/explain the SQL statement
the cursor is inside when nothing is selected, instead of the whole
file or a "pick a statement" popup. A subtle highlight shows which
statement is armed to run, and disappears once you make a selection.
Whole-file execution is still available by selecting all text first.
…h other

Running two different statements/tables back to back on the same tab
(now easy via cursor-driven Run) exposed two related bugs: an in-flight
column-metadata fetch could resolve after a newer run and overwrite it
with the wrong table's PK/columns, and every pagination/refresh action
(including post-edit-save refresh) re-sent the whole editor buffer
instead of the single statement that produced the current result,
which Postgres rejects as "multiple commands in a prepared statement"
when the buffer has more than one. Both are fixed by tracking the
exact last-run statement per tab and a generation counter that lets
stale async responses detect and drop themselves.
@maximumbreak
maximumbreak force-pushed the feature/run-statement-at-cursor branch from 4ca7ab7 to d9d3d65 Compare July 12, 2026 07:02
@maximumbreak maximumbreak changed the title feat(frontend): run statement at cursor on Cmd+Enter (TablePlus-style) feat(frontend): run statement at cursor on Cmd+Enter Jul 12, 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.

1 participant