Skip to content

fix(editor): keep Cmd+Delete and Option+Delete in the editor instead of the data grid (#2022) - #2025

Merged
datlechin merged 2 commits into
mainfrom
fix/2022-cmd-delete-focus
Aug 5, 2026
Merged

fix(editor): keep Cmd+Delete and Option+Delete in the editor instead of the data grid (#2022)#2025
datlechin merged 2 commits into
mainfrom
fix/2022-cmd-delete-focus

Conversation

@datlechin

Copy link
Copy Markdown
Member

Fixes #2022.

The bug

In a query tab, Cmd+Delete did nothing after running a SELECT, and once you had clicked a result row it deleted that row instead of the editor line. Reporter's clue: it worked when a -- comment preceded the query.

Root cause

TablePro separates grid shortcuts from editor shortcuts with the editor's local NSEvent monitor, which is gated on the editor being first responder and runs before the menu bar. That monitor only knows the editor's own combos (Cmd+/, Cmd+[, Cmd+], Cmd+Shift+D, Cmd+Shift+K, and friends).

AppKit's own text bindings are not in that list. Cmd+Delete (deleteToBeginningOfLine:) and Option+Delete (deleteWordBackward:) come from StandardKeyBinding.dict and resolve at the very end of dispatch, inside the first responder's keyDowninterpretKeyEvents. A main-menu key equivalent is matched long before that, so the Edit ▸ Delete item won every time. Its enabled state keyed on tab and selection state, never on focus:

Situation Menu item Result
After SELECT * FROM t;, nothing selected enabled claims the key, finds an empty selection, does nothing
Same, after clicking a result row enabled stages the row deletion while the editor has focus
-- comment first disabled the item stops claiming the key, editor deletes the line

Truncate Table on Option+Delete had the identical shape. With tables selected in the sidebar, deleting a word in the editor marked them for TRUNCATE instead.

The fix

A focus gate on data-grid menu commands whose binding duplicates one of AppKit's standard text-editing bindings.

  • ShortcutAction.standardTextEditingBindings lists those bindings, read off StandardKeyBinding.dict, and shadowsStandardTextEditingBinding(_:) reports a collision for .dataGrid-context actions only. Editor and global actions keep their shortcut by design; the settings recorder now warns about them instead.
  • MainContentCommandActions tracks focusOwnsTextInput from an NSWindow.didUpdateNotification observer, coalesced to the next runloop turn and written only on a transition. The test is firstResponder is NSTextInputClient, one predicate covering the SQL editor (CodeEditTextView.TextView is NSView-based but conforms), a field editor over a grid cell, and the sidebar filter field. NSTableView and NSOutlineView are excluded, so selecting rows or sidebar tables changes nothing.
  • View.dataGridShortcut(_:keyboard:yieldingTo:) applies the shortcut and drops it while the gate is on. It replaced optionalKeyboardShortcut at the 13 .dataGrid menu sites; it is inert at the 11 with no collision.

A menu item consumes a matching key equivalent whether or not it is enabled, so disabling alone would have left Cmd+Delete doing nothing. Dropping the key equivalent is the only way to hand the keystroke back, and it matches what this file already does for the Cmd+F route (TableProApp.swift).

Cmd+[ / Cmd+] and Cmd+Shift+D were checked and are not affected: the editor's local monitor already claims those before the menu sees them.

Scope

No default binding changed. Cmd+Delete for delete-row matches Finder and Mail, and is correct once the gate is; a bare Delete can never be a menu key equivalent because it would swallow backspace app-wide, and it already works through the grid's own keyDown.

Tests

  • KeyboardShortcutTests: new reserved-shortcut cases and a Standard text-editing bindings suite, including a guard that exactly delete and truncateTable shadow a system binding by default.
  • CommandActionsFocusGateTests: the gate yields for Delete and Truncate Table under text focus, and never for a non-colliding grid action, an editor action, or an unbound action.
  • QueryTabDeleteLineUITests: end-to-end through the real key-equivalent path, both halves of the reported repro. Note CI runs only TableProTests, so this one is local-only.

swiftlint lint --strict is clean. I could not build in this worktree (no Libs/*.a), so please surface any compile errors.

@mintlify

mintlify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
TablePro 🟢 Ready View Preview Aug 5, 2026, 12:09 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
@datlechin
datlechin merged commit 5993a98 into main Aug 5, 2026
3 checks passed
@datlechin
datlechin deleted the fix/2022-cmd-delete-focus branch August 5, 2026 12:21
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.

CMD + Delete not working correctly

1 participant