Skip to content

Commit

Permalink
web: improve getCommandById && improve remove from recents logic
Browse files Browse the repository at this point in the history
Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com>
  • Loading branch information
01zulfi committed Mar 3, 2025
1 parent 230d6d7 commit 8bdb8d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const CommandPaletteDialog = DialogManager.register(

const commands = usePromise(async () => {
select(0);
if (!defaultCommands.current)
defaultCommands.current = await getDefaultCommands();
const commands = props.isCommandMode
? sortCommands(commandSearch(query, defaultCommands.current))
Expand Down Expand Up @@ -280,9 +281,10 @@ export const CommandPaletteDialog = DialogManager.register(
{command.group === "recent" && (
<Button
title={strings.removeFromRecents()}
onClick={(e) => {
onClick={async (e) => {
e.stopPropagation();
removeRecentCommand(command.id);
defaultCommands.current = await getDefaultCommands();
commands.refresh();
}}
variant="secondary"
Expand Down
7 changes: 4 additions & 3 deletions apps/web/src/dialogs/command-palette/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,10 @@ export async function getDefaultCommands(): Promise<Command[]> {
}

export function getCommandById(id: string): Command | undefined {
return staticCommands
.concat(getEditorCommands())
.find((command) => command.id === id);
return (
staticCommands.find((command) => command.id === id) ||
getEditorCommands().find((command) => command.id === id)
);
}

export async function resolveRecentCommand(
Expand Down

0 comments on commit 8bdb8d6

Please sign in to comment.