I played a bit with the FuzzyMatcher implementation, but it seems to work alright. I tested the inputs from my first post against all Inkdrop commands using the matcher in a simple script, and it seems to work as expected.
The commands variable in the following is just the result of inkdrop.commands.findCommands({target: document.body})
function bestMatches(
query: string,
candidates: string[]
): Array<{ name: string; score: number }> {
const m = new FuzzyMatcher(query);
const res: Array<{ name: string; score: number }> = [];
for (const name of candidates) {
const r = m.match(name);
if (r) res.push({ name, score: r.score });
}
return res.sort((a, b) => b.score - a.score);
}
describe("FuzzyMatcher", () => {
it("core cut", () => {
const results = bestMatches(
"core cut",
commands.map((c: { displayName: any }) => c.displayName)
);
expect(results[0].name).toBe("Core: Cut");
console.log(results);
});
it("from selection", () => {
const results = bestMatches(
"from selection",
commands.map((c: { displayName: any }) => c.displayName)
);
expect(results[0].name).toBe("Core: New Note From Selection");
console.log(results);
});
});
I get the following as output:
stdout | test/fuzzyMatcher.commands.test.ts > FuzzyMatcher > core cut
[
{ name: 'Core: Cut', score: -1309 },
{ name: 'Core: Focus Next', score: -1316 },
{ name: 'Core: Focus Note List Bar', score: -1325 },
{ name: 'Core: Reload Package Updates', score: -1328 }
]
stdout | test/fuzzyMatcher.commands.test.ts > FuzzyMatcher > from selection
[ { name: 'Core: New Note From Selection', score: -929 } ]
This seems correct to me.