How to show NSPopover without dismissing the first responder?

195 Views Asked by At

I'm working on a mac app that has similar functionalities to the rocket app.

Whenever the user types : outside of my app I'll show an NSPopover with NSTableView near the cursor. The problem I'm facing here is that The moment I show the NSPopover it becomes the first responder and the user couldn't continue typing.

So I tried this, Showed the NSPopover without making a first responder, and used Global listener to listen UpArrow, DownArrow and Enter actions to navigate and select results. The downside of this approach: Let's say I'm composing a new mail, and the cursor responding to the up/down arrow events, eventually moved to other lines.

func showWidget(at origin: CGPoint, height: CGFloat) {
    let popUpView = NSView()
    let window: NSWindow = .getWindow(with: .init(width: 1, height: 1), origin: origin, withBorder: false)
    window.contentView?.setBackground(color: .white)
    window.contentView?.addSubview(popUpView)
    popUpView.alignEdges()
    popUpView.setBackground(color: .white)
    window.makeKeyAndOrderFront(nil)

    popover.contentViewController = widgetController
    popover.behavior = .semitransient
    popover.contentSize = .init(width: .inputWidgetSize.width, height: 200)
    popover.animates = false
    popover.appearance = NSAppearance.init(named: .darkAqua)
    popover.show(relativeTo: .init(origin: .init(x: .zero, y: 0), size: .init(width: .inputWidgetSize.width, height: height)), of: popUpView, preferredEdge: .maxY)
  }

Attaching video for reference: The functionality that I'm expecting

enter image description here

From my app

enter image description here

Note: Notice the cursor position to understand what going wrong.

0

There are 0 best solutions below