mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: command palette
supports searching by shortcut
This commit is contained in:
parent
72d6ee48fc
commit
08df140a55
1 changed files with 17 additions and 1 deletions
|
@ -780,13 +780,29 @@ function CommandPaletteInner({
|
||||||
const _query = deburr(
|
const _query = deburr(
|
||||||
commandSearch.toLocaleLowerCase().replace(/[<>_| -]/g, ""),
|
commandSearch.toLocaleLowerCase().replace(/[<>_| -]/g, ""),
|
||||||
);
|
);
|
||||||
matchingCommands = fuzzy
|
|
||||||
|
const matchingCommandsHaystack = fuzzy
|
||||||
.filter(_query, matchingCommands, {
|
.filter(_query, matchingCommands, {
|
||||||
extract: (command) => command.haystack,
|
extract: (command) => command.haystack,
|
||||||
})
|
})
|
||||||
.sort((a, b) => b.score - a.score)
|
.sort((a, b) => b.score - a.score)
|
||||||
.map((item) => item.original);
|
.map((item) => item.original);
|
||||||
|
|
||||||
|
const matchingCommandsShortcut = fuzzy
|
||||||
|
.filter(_query, matchingCommands, {
|
||||||
|
extract: (command) => command.shortcut || "",
|
||||||
|
})
|
||||||
|
.sort((a, b) => b.score - a.score)
|
||||||
|
.map((item) => item.original)
|
||||||
|
.filter(
|
||||||
|
(item) =>
|
||||||
|
!matchingCommandsHaystack.some((item2) => item.label === item2.label),
|
||||||
|
);
|
||||||
|
|
||||||
|
matchingCommands = matchingCommandsHaystack.concat(
|
||||||
|
matchingCommandsShortcut,
|
||||||
|
);
|
||||||
|
|
||||||
setCommandsByCategory(getNextCommandsByCategory(matchingCommands));
|
setCommandsByCategory(getNextCommandsByCategory(matchingCommands));
|
||||||
setCurrentCommand(matchingCommands[0] ?? null);
|
setCurrentCommand(matchingCommands[0] ?? null);
|
||||||
}, [commandSearch, allCommands, isCommandAvailable, lastUsed]);
|
}, [commandSearch, allCommands, isCommandAvailable, lastUsed]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue