diff --git a/menuffy/AppDelegate.swift b/menuffy/AppDelegate.swift index 85a5652..4905e6f 100644 --- a/menuffy/AppDelegate.swift +++ b/menuffy/AppDelegate.swift @@ -131,6 +131,9 @@ extension AppDelegate: NSTextFieldDelegate { let source2 = CGEventSource(stateID: CGEventSourceStateID.hidSystemState) let downArrowEvent = CGEvent(keyboardEventSource: source2, virtualKey: 0x7d, keyDown: true) downArrowEvent?.post(tap: CGEventTapLocation.cghidEventTap) + } else if commandSelector == #selector(NSResponder.insertNewline(_:)) { + let menuItem = menuView.filterdMenuItems[0] + NSApp.sendAction(menuItem.action!, to: menuItem.target, from: menuItem) } return false } diff --git a/menuffy/MainMenu/MenuView.swift b/menuffy/MainMenu/MenuView.swift index 748e54f..67158eb 100644 --- a/menuffy/MainMenu/MenuView.swift +++ b/menuffy/MainMenu/MenuView.swift @@ -12,6 +12,7 @@ class MenuView: NSView { var appMenu: NSMenu = NSMenu() private (set) public var allElements: [AXUIElement] = [] var allMenuItems: [NSMenuItem] = [] + var filterdMenuItems: [NSMenuItem] = [] var menuIndex: Int = 0 var topLevelMenuNum: Int = 0 @@ -27,6 +28,8 @@ class MenuView: NSView { } func filterMenuItem(keyword: String) { + + filterdMenuItems = [] // 検索時は既存のトップレベルメニューを隠す、空なら表示する let hidden = keyword == "" ? false : true for index in 1...topLevelMenuNum { @@ -47,6 +50,7 @@ class MenuView: NSView { if item.title.localizedCaseInsensitiveContains(keyword) { guard let copyItem = item.copy() as? NSMenuItem else { continue } appMenu.addItem(copyItem) + filterdMenuItems.append(copyItem) } } }