Skip to content

Commit 2cd5ae1

Browse files
committed
Bug Fixed: Not selecting second option as first arrow down
No execution action on enter key when no action is selected Resestting active command after palette is closed
1 parent 4ddfda7 commit 2cd5ae1

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

src/lib/components/CommandPalette.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
commands,
7575
storeMethods,
7676
actionMap,
77-
activeCommandId: commands?.[0]?.actionId || '',
77+
activeCommandId: null,
7878
results: commands
7979
}));
8080
};
@@ -84,7 +84,7 @@
8484
const unsubscribePaletteStore = paletteStore.subscribe((value: storeParams) => {
8585
isPaletteVisible = value.isVisible;
8686
actions = value.commands;
87-
activeCommand = value.activeCommandId ?? actions?.[0]?.actionId;
87+
activeCommand = value.activeCommandId ?? null;
8888
searchResults = getNonEmptyArray(value.results, value.commands, []);
8989
});
9090
@@ -125,7 +125,7 @@
125125
if (searchResults.length) {
126126
// get currently seleted item
127127
let activeCommandIndex = searchResults.findIndex((a) => a.actionId === activeCommand) ?? 0;
128-
activeCommandIndex = activeCommandIndex === -1 ? 0 : activeCommandIndex;
128+
activeCommandIndex = activeCommandIndex === -1 ? -1 : activeCommandIndex;
129129
const totalCommands = searchResults.length;
130130
const nextCommand = (activeCommandIndex + 1) % totalCommands;
131131
const indexToSet = searchResults[nextCommand] ? nextCommand : activeCommandIndex;
@@ -136,7 +136,7 @@
136136
const handleEnterKey = (event: KeyboardEvent) => {
137137
event.preventDefault();
138138
// get active command and execute
139-
const action = actionMap[activeCommand];
139+
const action = actionMap[activeCommand as string];
140140
runAction({ action });
141141
};
142142

src/lib/components/ResultPanel.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
1010
let actions: commands = [];
1111
const unsubscribe = paletteStore.subscribe((value: storeParams) => {
12-
actions = getNonEmptyArray(value.results);
12+
actions =
13+
value.results.length > 0 ? getNonEmptyArray(value.results) : getNonEmptyArray(value.commands);
1314
});
1415
1516
const themeContext = getContext(THEME_CONTEXT) as Writable<themeContext>;

src/lib/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type createActionMap from '$lib/utils/createActionMap';
22
import type createStoreMethods from '$lib/utils/createStoreMethods';
33

4-
export type ActionId = number | string;
4+
export type ActionId = number | string | null;
55
export type onRunParams = {
66
action: action;
77
storeProps: storeParams;
@@ -22,7 +22,7 @@ export type commands = Array<action>;
2222

2323
export interface storeParams {
2424
isVisible: boolean;
25-
textInput: '';
25+
textInput: string;
2626
commands: commands;
2727
storeMethods: ReturnType<typeof createStoreMethods>;
2828
actionMap: ReturnType<typeof createActionMap>;

src/lib/utils/createStoreMethods.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ const createStoreMethods = () => {
77
const storeProps: storeParams = get(paletteStore);
88

99
const resetPaletteStore = () => {
10-
paletteStore.update((n) => ({ ...n, defaultAppState }));
10+
paletteStore.update((n) => ({ ...n, ...defaultAppState }));
1111
};
1212

1313
const openPalette = () => {
1414
paletteStore.update((n) => ({ ...n, isVisible: true }));
1515
};
1616

1717
const closePalette = () => {
18-
paletteStore.update((n) => ({ ...n, isVisible: false }));
1918
resetPaletteStore();
2019
};
2120

src/lib/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ const updatePaletteStoreAfterActionExec = (actionId: ActionId) => {
4141
...n,
4242
isVisible: false,
4343
textInput: '',
44-
activeCommandId: actionId,
45-
selectedCommandId: actionId,
44+
activeCommandId: null,
45+
selectedCommandId: null,
4646
calledActions: [...n.calledActions, actionId]
4747
};
4848
});

src/routes/__layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<svelte:head>
77
<script>
88
const getThemeFromLocalStorage = () => {
9-
const theme = localStorage.getItem('theme') || 'dark';
9+
const theme = localStorage.getItem('theme') || 'light';
1010
return theme;
1111
};
1212

0 commit comments

Comments
 (0)