Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/lib/components/CommandPalette.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@
});

// When a result link has focus, move focus with the highlight so Enter opens the highlighted one.
async function followSelection() {
// Pointer moves pass preventScroll, so the list doesn't slide another result under the cursor.
async function followSelection(preventScroll = false) {
const active = document.activeElement;
if (!(active instanceof HTMLAnchorElement) || !dialogEl?.contains(active)) return;
await tick();
dialogEl.querySelectorAll<HTMLAnchorElement>('a[data-result]')[selectedIndex]?.focus();
dialogEl.querySelectorAll<HTMLAnchorElement>('a[data-result]')[selectedIndex]?.focus({ preventScroll });
}

// Keep Tab inside the open dialog.
Expand Down Expand Up @@ -271,7 +272,7 @@
// mousemove, not mouseenter: scrolling under a still pointer fires enter only.
if (selectedIndex === index) return;
selectedIndex = index;
followSelection();
followSelection(true);
}}
onfocus={() => (selectedIndex = index)}
onclick={() => (open = false)}
Expand Down
Loading