Skip to content

Commit

Permalink
save search query, and restore on cmd-K
Browse files Browse the repository at this point in the history
closes #889
  • Loading branch information
Fil committed Mar 7, 2024
1 parent 001ee14 commit 1a91d4c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/client/search-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ addEventListener("keydown", (event) => {
// persistently after you blur the search input.)
toggle.classList.add("observablehq-sidebar-open");
input.focus();
input.value = sessionStorage.getItem("search-query") ?? "";
input.select();
event.preventDefault();
}
Expand Down
1 change: 1 addition & 0 deletions src/client/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const index = await fetch(import.meta.resolve(global.__minisearch))
input.addEventListener("input", () => {
if (currentValue === input.value) return;
currentValue = input.value;
sessionStorage.setItem("search-query", currentValue);
if (!currentValue.length) {
container.setAttribute("data-shortcut", shortcut);
sidebar.classList.remove("observablehq-search-results");
Expand Down

0 comments on commit 1a91d4c

Please sign in to comment.