fix(datagrid): reload the structure grid on filter and sort instead of showing stale rows#1840
Merged
Merged
Conversation
…f showing stale rows
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
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.
Problem
The Structure tab's Filter field and column sort showed stale rows. Typing in the filter changed the visible row count but the cell text stayed wrong, and sorting a column often did nothing.
Root cause
The Structure grid rebuilds its rows on every filter/sort with positional row IDs. The grid only reloads when its
DataGridUpdateSnapshotchanges, and that snapshot tracks row count, columns, andreloadVersion, not which rows are shown. The display cache is keyed by row ID and is only cleared on areloadVersionbump. A filter or sort bumps neither, soreloadData()was skipped whenever the row count stayed the same, and the cache returned the previous rows' text for the reused positional IDs.Fix
Thread the Structure view's existing content counter (
displayVersion) into the grid as a genericcontentRevision. A change in it counts as a content change, which already drives both display-cache invalidation andreloadData(). This runs on one deterministic path inupdateNSViewand fixes filter and sort at any row count. The other grids (data tab, inspector, create table) pass the default0and are unaffected.Behavior stays as documented: live, name-only filtering and header-click sort. This matches Apple's contract that visible cells only reflect new data after
reloadData()/reloadData(forRowIndexes:), and the data tab's own content-replace pattern (invalidate the cache, then reload).Tests
contentRevisionchange at a constant row count.StructureRowProviderfilters by name (case-insensitive) and keepsfilteredToSourceMapaligned across filter and sort.Notes
displayIDs == nil, so the edit/delete/copy index translation and the "selection indices are display positions" invariant are untouched.swiftlint --strictclean on the changed files.