feedback-assistant / reports

Open collection of Apple Feedback Assistant reports

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FB12938907: NSMenu not properly updated when adding/removing NSMenuItem

p0deje opened this issue · comments

  • Date: 2023-08-12
  • Resolution: Open
  • Area: AppKit
  • OS: macOS 14.0
  • Type: Incorrect/Unexpected Behavior
  • Keywords: NSMenu

Description

Maccy dynamically adds/removes items in NSMenu to support searching across the items. In certain cases, this seems to completely break the NSMenu items list and its order. Here are exact steps to reproduce:

  1. Start Maccy app.
  2. Copy the following items to the system clipboard one by one: “one, two, three, four, five”.
  3. Click Maccy icon in menubar and click “Preferences …”
  4. In “Appearance” tab, set “Number of items” to 3. This will make only “five”, “four” and “three” visible in Maccy.
  5. Close “Preferences…”.
  6. Click Maccy icon in menubar.
  7. Click search field and type “five”.

Expected: The menu includes “five”, then separator item followed by “Clear”, “Preferences…”, “About” and “Quit”.
Actual: The menu includes “five” and “three”, whilst “Quit” is missing. Pressing “Shift” on keyboard moves “Clear all” higher.

Whilst debugging, I can clearly see that printing NSMenu.items shows the proper list of items (“five” with its 2 alternate items and no “three”):

[
  <NSMenuItem: 0x600001bcfe20 Maccy>,
  <_TtCC5Maccy15HistoryMenuItem12CopyMenuItem: 0x6000005e4e40 five, ke='Command-1'>,
  <_TtCC5Maccy15HistoryMenuItem13PasteMenuItem: 0x6000005e5800 five, ke='Option-1', hidden>,
  <_TtCC5Maccy15HistoryMenuItem30PasteWithoutFormattingMenuItem: 0x6000005e5980 five, ke='Option-Shift-1', hidden>,
  <_TtCC5Maccy15HistoryMenuItem15PreviewMenuItem: 0x600001eeb980 , hidden>,
  <NSMenuItem: 0x600001bc1ab0 >,
  <NSMenuItem: 0x600001bc1c00 Clear, ke='Option-Command-⌫'>,
  <NSMenuItem: 0x600001be92d0 Clear all, ke='Option-Shift-Command-⌫', hidden>,
  <NSMenuItem: 0x600001bd4000 Preferences..., ke='Command-,'>,
  <NSMenuItem: 0x600001bc1dc0 About>,
  <NSMenuItem: 0x600001bcb790 Quit, ke='Command-Q'>
]

Maccy is an open source and the whole code for adding/removing items can be seen in https://github.com/p0deje/Maccy/blob/5f85851571ecb1e91e77e3ff603b187473bf9d00/Maccy/Menu.swift#L234-L270. It’s a lot of hard-to-read code, but it essentially boils down to adding/inserting/removing items in https://github.com/p0deje/Maccy/blob/5f85851571ecb1e91e77e3ff603b187473bf9d00/Maccy/Menu.swift#L546-L569.

Files

Screenshot 2023-08-12 at 09 06 53