Skip to content

Fix incremental update misalignment with insert/remove around image items#483

Draft
wojo wants to merge 1 commit intoswiftbar:mainfrom
wojo:fix/image-incremental-update
Draft

Fix incremental update misalignment with insert/remove around image items#483
wojo wants to merge 1 commit intoswiftbar:mainfrom
wojo:fix/image-incremental-update

Conversation

@wojo
Copy link
Copy Markdown
Contributor

@wojo wojo commented Mar 25, 2026

Summary

Fixes #482 — the positional diff in diffMenuNodes() misaligns items when inserts or removes shift indices, causing image items to inherit adjacent text as their attributedTitle (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 existing NSMenuItems. 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

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
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.

Incremental update misaligns items around large images, rendering ghost text beside image

1 participant