timc1 / kbar

fast, portable, and extensible cmd+k interface for your site
https://kbar.vercel.app
MIT License
4.87k stars 184 forks source link

Possibility to define actions that are always shown / never filtered out from the results list #286

Closed aghster closed 1 year ago

aghster commented 1 year ago

I would like to be able to define actions that are always part of the results list, irrespecitve of the current search string. However, this is not possible, because actions for which command-score returns 0 will not be included in the results list due to:

https://github.com/timc1/kbar/blob/54b9fd8397f4bc1ad90833d1586f6f0bd0785e07/src/useMatches.tsx#L196-L198

My suggestion is that any action whose keywords include a special wildcard keyword will always be included in the results list. For example this special wildcard keyword could be *.

As it seems, this could easily be implemented by ameding the above condition as follows:

      if (score > 0 || action.keywords?.split(" ").indexOf("*") !== -1) {
        matches.push({ score, action });
      }

@timc1, would you consider this generally useful and add this feature to kbar?

timc1 commented 1 year ago

@aghster I'm open to it – curious what are some of those actions you had in mind that would always be part of the list?

aghster commented 1 year ago

In my use case I have only two or three static actions, but depending on the search string more actions are dynamically added. However, I want the static actions to be always quickly accessible, even if a search string was entered that does not match these actions.

eMerzh commented 1 year ago

I have a usecase where i have a few "action" like

but i also want to fallback to an action where i go "Search ${query}" where you launch a full faceted search with the current search term but ability to add a bunch of stuff

for that i need to be able to append a * query , and be able to use the search term in the perform & the action name

Itsnotaka commented 1 year ago

I agree with this idea; it would be nice to have some actions to fallback on instead of showing nothing or an empty component that can't perform any actions.

stale[bot] commented 1 year ago

Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

eMerzh commented 1 year ago

I'm interested in this... Please do not close 😁

stale[bot] commented 1 year ago

Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.