command-pal icon indicating copy to clipboard operation
command-pal copied to clipboard

add aliases search array and display best matches for aliases to user

Open rouilj opened this issue 2 years ago • 6 comments

Note: This upgrades the required version of fuse.js to 6.6.2. This version allows weighting to be properly specified.

This adds an aliases array for each command. A match in the alias has a weight of 2x compared to the name or description fields. If the user enables the displayHints option, the best matching alias will be appended to the end of the command name. This is useful for listing alternate terms for the one that is chosen as the command name. For example:

name: emacs, alias: editor

will show up as emacs (editor) if the user typed edit.

The README.md has more info.

This was inspired by the implementation of synonyms described at:

https://blog.superhuman.com/how-to-build-a-remarkable-command-palette/#rule-4-build-flexibility-into-your-command-palette

rouilj avatar Feb 05 '23 10:02 rouilj

This addresses #8.

rouilj avatar Feb 05 '23 18:02 rouilj

I forgot to mention that this also changes the sortFn used by fuse.js. I presort my command array by weight. I want the search results to take this into account.

If two commands are close enough to each other (< 0.05 difference in scores) they don't sort by score but by their order in the commands array. With lower indexes sorting first. 0.05 is a magic number that produced the results I wanted in a couple of tests but I didn't try to optimize it (or understand the underlying algorithm for the scores).

rouilj avatar Feb 05 '23 19:02 rouilj

I've been looking at this for a while, I can see the benefit and it's the whole reason I used fuse.js. I feel it could be a lot simpler though, and docs will need some work (after)

If there is a way to make fuse.js apply a weight to an object, I didn't see it. All I saw was weights on the fields in the object.

Maybe merge in the latest master if you get a chance too

Working on it now.

rouilj avatar Feb 11 '23 02:02 rouilj

I think I got this right. I don't use git or GitHub much. My preferrd DVCS is Fossil because well, I'm a fossil 8-). Take another look.

Also nice use of ChatGpt. what did you feed it to get it to generate the refactored code? It may not be as performant, but it certainly is much easier. If I had written it as refactored I would probably have finished writing it much more quickly 8-).

rouilj avatar Feb 11 '23 03:02 rouilj

I think I got this right. I don't use git or GitHub much. My preferrd DVCS is Fossil because well, I'm a fossil 8-). Take another look.

Looks good, I'll fix the type errors in the next few days, probably makes sense to put this in a filtering.ts file I think

Also nice use of ChatGpt. what did you feed it to get it to generate the refactored code? It may not be as performant, but it certainly is much easier. If I had written it as refactored I would probably have finished writing it much more quickly 8-).

It's amazingly flexible this, you can be pretty expressive and just paste code in below it

Can you make this JS code a bit easier to read, remove the comment, and add named boolean variables before returning:
(and then pasted code below it)

benwinding avatar Feb 11 '23 03:02 benwinding

One thing I would leave the comment that 0.05 and 0.009 are magic numbers with little if any research to justify them.

rouilj avatar Feb 11 '23 22:02 rouilj