refactor(datagrid): direct-draw NSView cell, subview-based overlay editor#1135
Merged
refactor(datagrid): direct-draw NSView cell, subview-based overlay editor#1135
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the 97% CPU spike during sustained scroll over the data grid. Replaces the
NSTableCellView+NSTextField+NSButton+ Auto Layout cell with a direct-drawNSView, and replaces theNSPanel-based overlay editor with a subview of the table view so the parent window stays key during edit (toolbar/buttons keep their accent color).What changed
DataGridCellView:NSTableCellView→NSViewdirect-drawNSTextField/NSButtonper celldraw(_:)paints text via cachedNSAttributedString(invalidated only on text/font/color change), then accessory icon (FK arrow or chevron), then optional focus borderNSCellinternal layout, zeroNSButtontracking-area workNSColor.alternateSelectedControlTextColor(white) when on emphasized selection, falling back to.labelColorotherwise. Matches macOS HIG.NSImage.SymbolConfiguration(hierarchicalColor:)(correct API for multi-layer symbols likearrow.right.circle.fill); two cached variants per icon (normal + emphasized)menu(for:)for context menusDataGridRowView: emphasis propagation to cell subviewsisSelectedandisEmphasizedsetters to callsetNeedsDisplay(true)on everyDataGridCellViewsubview when emphasis changes.NSTableCellViewgot this for free viainteriorBackgroundStyleinheritance from NSCell binding; customNSViewcells need explicit propagation. Without this, only the focused cell would flip text color on row select; sibling cells stayed black.CellOverlayEditor:NSPanel→ subview of the table viewisFieldEditor = true) is now added as a subview of the table view in the same windowNSEvent.addLocalMonitorForEventsNSApplication.didResignActiveNotificationEditing path consolidation
tableView(_:shouldEdit:row:)is now a no-op (AppKit doesn't invoke it for custom NSView cells anyway)beginCellEdit(row:tableColumnIndex:)onTableViewCoordinatoris the single entry point — called from double-click, single-click-on-focused, Return key, programmaticbeginEditing. Routes toeditEligibilitythenshowOverlayEditor.CellTextField.swift(83 LoC),DataGridFieldEditor, thewindowWillReturnFieldEditorbranch onTabWindowController, theNSControlTextEditingDelegate/NSTextFieldDelegateconformances onTableViewCoordinator, and therestoreTruncatedDisplayglueResize cursor fix
NSTableHeaderViewauto-handles the resize cursor whencolumn.resizingMask.contains(.userResizingMask). That auto-mechanism doesn't fire for subclassedNSTableHeaderViewinstances on macOS 14+. Restored theupdateTrackingAreas+mouseMovedcursor handling inSortableHeaderView. (Tested:resetCursorRectsalone doesn't fire reliably for our subclass;mouseMoveddoes.)Diff stats
CellTextField.swift)Test plan
stress_datafromdocs/test/sample_postgres_02_data.sql). Sustained scroll (hold arrow, drag scrollbar). CPU should stay reasonable; no 97% spike.