@@ -3095,26 +3095,49 @@ extension MenuBarItemManager {
30953095 """
30963096 )
30973097
3098+ // For the hidden/alwaysHidden sections, use the control item as the anchor
3099+ // rather than a saved item. This prevents new items (like wispr-flow) that
3100+ // appear on the right side from being used as anchors, which would cause
3101+ // the saved items to be placed in reverse order.
3102+ let useControlItemAsAnchor : Bool
3103+ let anchorControlItem : MenuBarItem ?
3104+ switch sectionName {
3105+ case . hidden:
3106+ useControlItemAsAnchor = true
3107+ anchorControlItem = controlItems. hidden
3108+ case . alwaysHidden:
3109+ useControlItemAsAnchor = true
3110+ anchorControlItem = controlItems. alwaysHidden
3111+ case . visible:
3112+ useControlItemAsAnchor = false
3113+ anchorControlItem = nil
3114+ }
3115+
30983116 // Find the first valid anchor that is not temporarily shown.
30993117 var anchorIndex = 0
31003118 var anchor : MenuBarItem ?
3101- while anchorIndex < filteredSaved. count {
3102- guard let candidate = itemsByID [ filteredSaved [ anchorIndex] ] else {
3103- anchorIndex += 1
3104- continue
3105- }
3106- let tagString = " \( candidate. tag. namespace) : \( candidate. tag. title) "
3107- if activelyShownTags. contains ( tagString) {
3108- anchorIndex += 1
3109- continue
3119+ if useControlItemAsAnchor, let controlItem = anchorControlItem {
3120+ anchor = controlItem
3121+ } else {
3122+ while anchorIndex < filteredSaved. count {
3123+ guard let candidate = itemsByID [ filteredSaved [ anchorIndex] ] else {
3124+ anchorIndex += 1
3125+ continue
3126+ }
3127+ let tagString = " \( candidate. tag. namespace) : \( candidate. tag. title) "
3128+ if activelyShownTags. contains ( tagString) {
3129+ anchorIndex += 1
3130+ continue
3131+ }
3132+ anchor = candidate
3133+ break
31103134 }
3111- anchor = candidate
3112- break
31133135 }
31143136 guard let anchor else { continue }
31153137
3116- // Move items right-to-left: the anchor is the rightmost valid item;
3117- // each subsequent item is placed to its left.
3138+ // Move items to restore saved order. For hidden/alwaysHidden sections,
3139+ // move items to the right of the anchor (control item). For visible,
3140+ // move items to the left of the anchor.
31183141 var currentAnchor = anchor
31193142 for i in ( anchorIndex + 1 ) ..< filteredSaved. count {
31203143 guard let item = itemsByID [ filteredSaved [ i] ] else { continue }
@@ -3124,7 +3147,16 @@ extension MenuBarItemManager {
31243147 guard !activelyShownTags. contains ( tagString) else { continue }
31253148
31263149 do {
3127- try await move ( item: item, to: . leftOfItem( currentAnchor) , skipInputPause: true )
3150+ let destination : MoveDestination
3151+ if useControlItemAsAnchor {
3152+ // For hidden sections, place items to the right of the anchor
3153+ // (towards the visible section).
3154+ destination = . rightOfItem( currentAnchor)
3155+ } else {
3156+ // For visible section, place items to the left of the anchor.
3157+ destination = . leftOfItem( currentAnchor)
3158+ }
3159+ try await move ( item: item, to: destination, skipInputPause: true )
31283160 didMove = true
31293161 // Only advance the anchor after a successful move so that
31303162 // the next item targets the last correctly placed position.
0 commit comments