Skip to content

fix(datagrid): edit date cells inline and add date presets to Set Value - #1233

Merged
datlechin merged 4 commits into
mainfrom
fix/datagrid-date-cell-edit
May 12, 2026
Merged

datlechin merged 4 commits into
mainfrom
fix/datagrid-date-cell-edit

Conversation

@datlechin

@datlechin datlechin commented May 12, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Removes the NSDatePicker popover for date / datetime / timestamp cells. Those cells now use the same inline text overlay editor as every other column: double-click, type, Return.
  • Right-click Set Value submenu on date-like cells gains current-value SQL function presets, filtered by column type:
    • DATE columns → CURRENT_DATE
    • TIME / TIMETZ columns → CURRENT_TIME
    • DATETIME / TIMESTAMP columns → NOW(), CURRENT_TIMESTAMP
  • Presets are written as raw SQL function expressions; SQLStatementGenerator already routes them through SQLEscaping.isTemporalFunction so they emit unquoted (no parameter binding).
  • Drops the .date case from DataGridCellKind and the chevron accessory from date cells. DatePickerCellEditor.swift deleted entirely (-233 LOC).

Other fixes folded in

  • Editing a NULL cell and dismissing without typing no longer flips the value to an empty string. CellOverlayEditor now tracks the initial value and skips onCommit when the value is unchanged.
  • Double-clicking another cell while editing no longer drops the previous edit or stalls the new editor — the outside-click monitor runs synchronously via MainActor.assumeIsolated instead of deferring through Task { @MainActor … }.
  • Data grid cells with a chevron accessory (enum, boolean, JSON, blob) no longer truncate short values that fit the full cell width.
  • DATE columns no longer render a phantom 00:00:00 time suffix; DateFormattingService now picks the right formatter bucket (date-only, time-only, datetime) per column type, and the format cache is keyed by bucket.
  • Cmd+Z crash fix: OverlayTextView gets its own private UndoManager so typing-undo no longer pollutes the window's undo stack; dismissing the editor used to leave dangling text-view targets that crashed objc_msgSend on the next Cmd+Z.
  • Editor lifecycle on row mutations: applyDelta for .rowsInserted, .rowsRemoved, .columnsReplaced, and .fullReplace now dismisses the active overlay editor. This means any row insertion or removal (Add Row, paste rows, undo, full reload, schema change) closes the editor — not just Add Row + Cmd+Z. The editor's row anchor would be stale otherwise.
  • Editor z-order during insert animation: KeyHandlingTableView.didAddSubview re-raises the editor's container whenever NSTableView adds a sibling subview (the animation-deferred row view used to render on top of the auto-opened editor).
  • Undo routes through the first responder: Edit > Undo and Edit > Redo now send undo: / redo: via NSApp.sendAction(_:to:nil) before falling back to the window's undo manager. Cmd+Z while editing now undoes typing in the overlay editor instead of jumping straight to data-grid changes.

FK preview popover follows the selection

  • New @Observable FKPreviewModel (cellValue + fkInfo) drives ForeignKeyPreviewView; the view re-runs its fetch via .task(id:) when either changes.
  • tableViewSelectionDidChange calls refreshFKPreviewForRowChange(), which updates model.cellValue, model.fkInfo, and popover.positioningRect in place — no close-and-reopen.
  • KeyHandlingTableView arrow-left / arrow-right call coordinator?.dismissFKPreviewOnColumnChange() since FK metadata is column-scoped.
  • Row mutations also dismiss (anchor would be stale).
  • Row tracking uses keyTableView.focusedRow first, then selectedRowIndexes.max(), so the popover follows even during Shift+arrow extend-selection.

Why

The original popover was only reachable via the chevron on date cells; double-click and the inline edit path were both explicitly blocked. The popover was effectively dead code. Folding date cells into the standard overlay editor removes a special-case path and ~233 LOC, and the Set Value submenu gives one-click access to the standard SQL function presets users already expect.

DATE presets are restricted to CURRENT_DATE rather than including NOW() / CURRENT_TIMESTAMP so the feature works on Postgres without explicit casts. Same reasoning for TIME → CURRENT_TIME.

Test plan

  • Double-click a DATE cell → inline text editor opens with the current value. Type a new date, Return commits.
  • Double-click a TIMESTAMP / DATETIME cell → same inline editor.
  • Right-click a DATE cell → Set Value submenu lists CURRENT_DATE; choose it and Save → SQL preview emits CURRENT_DATE unquoted.
  • Right-click a TIMESTAMP cell → submenu lists NOW() and CURRENT_TIMESTAMP.
  • Right-click a TIME column → submenu lists CURRENT_TIME.
  • Open an editor on a NULL cell, click out without typing → cell stays NULL and row is not marked modified.
  • Edit cell A, then double-click cell B → A's edit commits, B's editor opens immediately.
  • Boolean / JSON / blob cells: short values render without trailing ellipsis.
  • Date cells no longer render a chevron accessory.
  • Add Row → type → click out → Cmd+Z several times. No crash. Row removes; editor dismisses with it.
  • Type in the editor, press Cmd+Z. Typing is undone, not a data-grid action.
  • Add Row while another editor is open → previous editor commits, new row appears, new editor opens on top of the inserted row (no animation race).
  • Space on an FK cell → popover opens. Arrow up/down → popover follows the selection, content updates per row. Arrow left/right → popover closes. Shift+Down → popover follows the extended row.

@datlechin
datlechin force-pushed the fix/datagrid-date-cell-edit branch 6 times, most recently from 4a31c15 to 26b2f7a Compare May 12, 2026 10:08
@datlechin
datlechin force-pushed the fix/datagrid-date-cell-edit branch from 26b2f7a to 4c1539f Compare May 12, 2026 10:14
@datlechin
datlechin merged commit d5d53ce into main May 12, 2026
1 check passed
@datlechin
datlechin deleted the fix/datagrid-date-cell-edit branch May 12, 2026 12:42
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