cmdk icon indicating copy to clipboard operation
cmdk copied to clipboard

Export of commandScore?

Open goatyeahh opened this issue 6 months ago • 1 comments

Would you consider exporting commandScore? I like the default commandScore, but it would be great to reuse it.

CleanShot 2024-08-05 at 13 06 14@2x

Why?

My first use case is that I have added some unique value to my command items to avoid name clash issues that interfere with the search like suggested here https://github.com/pacocoursey/cmdk/issues/174

<Command.Item value="apple __a__">Apple</Command.Item>
<Command.Item value="apple __b__">Apple</Command.Item>

so something like this would do the trick

  filter={(value: string, search: string, keywords?: string[]) => {
    // value: `<name> __${unique}__)`
    const valueWithoutUnique = value.replace(/\s+__\s+__/, "");
    return commandScore(valueWithoutUnique, search, keywords);
  }}

or another use case would be to change filter only for some specific keyword and for others leave the default.

goatyeahh avatar Aug 05 '24 11:08 goatyeahh