Fix incremental update misalignment with insert/remove around image items#483
Draft
wojo wants to merge 1 commit intoswiftbar:mainfrom
Draft
Fix incremental update misalignment with insert/remove around image items#483wojo wants to merge 1 commit intoswiftbar:mainfrom
wojo wants to merge 1 commit intoswiftbar:mainfrom
Conversation
The positional diff in diffMenuNodes() compares items by index. When items are inserted or removed, all items after the change point shift indices and get patched with the wrong content. For image items, this causes adjacent text to appear as the attributedTitle (rendered to the right of the image), and cached layout heights become stale. Fall back to a full menu rebuild when the diff contains structural changes (inserts or removes). The incremental path is preserved for the common case where item count is unchanged. Fixes swiftbar#482
This was referenced Mar 25, 2026
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 #482 — the positional diff in
diffMenuNodes()misaligns items when inserts or removes shift indices, causing image items to inherit adjacent text as theirattributedTitle(rendered to the right of the image).Changes
When the incremental diff contains structural changes (inserts or removes), fall back to a full menu rebuild instead of patching in-place. The positional diff is only safe when item count is unchanged and items map 1:1 by index.
Why this approach
The positional diff compares items at the same index. When items are inserted or removed, all items after the change point shift, and
patchMenuItem()applies the wrong params to existingNSMenuItems. For image items, this means a text title gets set alongside the image, and cached layout heights become stale.A proper LCS-based diff would fix the root cause but is a larger change. This fallback is safe and preserves the incremental update benefit for the common case (same structure, values change).
Test plan