Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quickActionBarDidCancel not being called when user clicks outside the bar #3

Closed
cyrilzakka opened this issue Dec 10, 2022 · 6 comments
Assignees

Comments

@cyrilzakka
Copy link

cyrilzakka commented Dec 10, 2022

Hello, I hope you're well! I'm having an issue whereby after clicking outside the search bar, it stops showing up on subsequent calls, even though isPresenting is logging the correct values.

In other words, quickActionBarDidCancel is called when the user pressed esc but not when clicking outside the bar. Currently being called as so:

self.quickActionBar.present(placeholderText: "Search...", width: self.screenWidth)

Otherwise when presenting the bar with the completion handler, the statement is logged, but the bar stop showing up on subsequent calls to present.

self.quickActionBar.present(placeholderText: "Search...", width: self.screenWidth) {
			Swift.print("Quick action bar closed")
}

Any help would be greatly appreciated!

@dagronf
Copy link
Owner

dagronf commented Dec 11, 2022

If your application is not frontmost (ie the window that accepts events), the quick action bar will not be presented (as the quick action bar window cannot become main window IF the application is not frontmost.)

Using the code you provided in #2, adding

NSApp.activate(ignoringOtherApps: true)

to the start of the toggleSearch function solves the issue.

@objc func toggleSearch(_ sender: Any?) {

   NSApp.activate(ignoringOtherApps: true)

   if quickActionBar.isPresenting {
      // Hide
      quickActionBar.cancel()
   } else {
      // Show
      self.quickActionBar.present(
         parentWindow: nil,
         placeholderText: "Search Filters",
         searchImage: NSImage(systemSymbolName: "books.vertical", accessibilityDescription: "books.vertical"),
         width: min(800, max(500, 200 + 50))
      ) {
         Swift.print("Quick action bar closed")
      }
   }
}

Please let me know if this solves your issue.

@dagronf
Copy link
Owner

dagronf commented Dec 11, 2022

I'm not sure whether I should automatically call NSApp.activate(...) when presenting the window (is this more restrictive for the library user?) 🤔

@dagronf
Copy link
Owner

dagronf commented Dec 11, 2022

Okay I've added the call to the present method within the library. If you update to the current latest version (4.2.2) this should resolve your issue.

dagronf added a commit that referenced this issue Dec 11, 2022
@cyrilzakka
Copy link
Author

Perfect thank you! I've made changes to the bar to make copy/paste/cut/select all work in the NSTextField even with a menu bar app. I've also modified the appearance (background and height) to make it match Spotlight Search a bit more. Would you like me to submit a pull request?

@dagronf
Copy link
Owner

dagronf commented Dec 11, 2022

Absolutely! I’d love to see what you’ve done.

@dagronf dagronf self-assigned this Dec 11, 2022
@cyrilzakka
Copy link
Author

cyrilzakka commented Dec 14, 2022

Great will do so asap! Honestly it's not much compared to what you've done with this library, looks great! Just looking into accessing row indices to display different views for items (unfortunately the search term isn't enough)

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

No branches or pull requests

2 participants