Skip to content

fix: Ctrl+Enter always runs query in the last opened console tab#240

Merged
debba merged 1 commit into
TabularisDB:mainfrom
thomaswasle:bug/keyboard-shortcut-console
May 21, 2026
Merged

fix: Ctrl+Enter always runs query in the last opened console tab#240
debba merged 1 commit into
TabularisDB:mainfrom
thomaswasle:bug/keyboard-shortcut-console

Conversation

@thomaswasle
Copy link
Copy Markdown
Contributor

Problem

When multiple Console tabs are open, Ctrl+Enter always executed the query of the last opened
tab
instead of the tab currently in the foreground.

Root cause

Monaco's editor.addCommand() registers keybindings in a global registry — last registration
wins across all editor instances on the page. Two compounding issues caused this:

  1. Editor.tsx – stale closure + global override
    handleEditorMount called editor.addCommand(CtrlCmd+Enter, handleRunButton), where
    handleRunButton is a useCallback that closes over activeTab at the time of registration.
    Because onMount is only passed for the active tab, this command was registered anew every
    time a tab was opened — each time globally overriding the binding for all editors with a
    handler still pointing to the newly opened tab.

  2. SqlEditorWrapper.tsx – stale closure
    The addCommand closure captured onRun once at editor mount time. Even when the parent
    re-rendered with a fresh handleRunButton, the Monaco command kept calling the original stale
    reference.

Fix

SqlEditorWrapper.tsx — introduce onRunRef updated synchronously on every render. The
addCommand closure reads onRunRef.current so it always dispatches to the current handler
regardless of when the editor mounted.

Editor.tsx — remove the duplicate addCommand(CtrlCmd+Enter, handleRunButton) from
handleEditorMount. SqlEditorWrapper already owns this binding; the Editor.tsx call existed
only to override it with a stale closure on each new tab open.

Behaviour after fix

  • Ctrl+Enter (and Cmd+Enter on macOS) executes the query in whichever Console tab is
    currently active, regardless of how many tabs are open or the order in which they were opened.
  • The run-selection and explain-selection context-menu actions are unaffected (they already
    used stable refs via addAction).

@kilo-code-bot
Copy link
Copy Markdown

kilo-code-bot Bot commented May 21, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • src/components/ui/SqlEditorWrapper.tsx — Fix stale closure by introducing onRunRef updated synchronously on every render; the addCommand closure reads onRunRef.current so it always dispatches to the current handler.
  • src/pages/Editor.tsx — Removed duplicate editor.addCommand(Ctrl+Enter, handleRunButton) from handleEditorMount. The binding is now owned exclusively by SqlEditorWrapper.

Reviewed by kimi-k2.6 · 310,852 tokens

@debba
Copy link
Copy Markdown
Collaborator

debba commented May 21, 2026

Awesome as usual :)

@debba debba merged commit d8f9feb into TabularisDB:main May 21, 2026
2 checks passed
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.

2 participants