From c0227663a940cbdbdfa0651103a9e48125c107a7 Mon Sep 17 00:00:00 2001 From: trickypr <23250792+trickypr@users.noreply.github.com> Date: Tue, 14 Nov 2023 22:39:11 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Generate=20suggestions=20on=20fo?= =?UTF-8?q?cus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/content/browser/Browser.svelte | 2 +- .../components/keybindings/Keybinding.svelte | 6 ++--- .../components/toolbar/HamburgerMenu.svelte | 8 +++--- .../components/toolbar/omnibox/Omnibox.svelte | 25 ++++++++++++------- src/content/credits/Credits.svelte | 2 +- src/content/settings/Settings.svelte | 2 +- .../settings/components/Category.svelte | 2 +- .../shared/components/FancySelect.svelte | 4 +-- 9 files changed, 31 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 71a9d34..aa959f2 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "dev-actors": "tsc -w -p ./tsconfigs/tsconfig.actors.json", "rt:slink": "rm --force ./.store/artifact.tar.bz2 && ln -s ../../experiment-runtime/dist/experiment-runtime-1.0.0.en-US.linux-x86_64.tar.bz2 ./.store/artifact.tar.bz2", "lint": "eslint .", - "format": "pnpm lint && pnpm script:license-check --fix && prettier . --write", + "format": "pnpm lint && pnpm script:license-check --fix && prettier . --write --plugin prettier-plugin-svelte", "data": "concurrently -c auto pnpm:data:*", "data:tld": "wget https://data.iana.org/TLD/tlds-alpha-by-domain.txt -O ./src/content/shared/search/providers/data/tld.txt" }, diff --git a/src/content/browser/Browser.svelte b/src/content/browser/Browser.svelte index d00b6ad..f882046 100644 --- a/src/content/browser/Browser.svelte +++ b/src/content/browser/Browser.svelte @@ -15,7 +15,7 @@ // We don't care about the order that browers are rendered in the dom, but we // want to allow tab reordering. This should stop unnessisary updates $: sortedBrowers = [...$tabs].sort( - (tabA, tabB) => tabA.getId() - tabB.getId() + (tabA, tabB) => tabA.getId() - tabB.getId(), ) diff --git a/src/content/browser/components/keybindings/Keybinding.svelte b/src/content/browser/components/keybindings/Keybinding.svelte index cd0c406..2f51b01 100644 --- a/src/content/browser/components/keybindings/Keybinding.svelte +++ b/src/content/browser/components/keybindings/Keybinding.svelte @@ -9,15 +9,15 @@ export let pref: string let keybind: Keybind = keybindFromString( - Services.prefs.getStringPref(pref, '') + Services.prefs.getStringPref(pref, ''), ).unwrap() onMount(() => { const observer = observable( () => (keybind = keybindFromString( - Services.prefs.getStringPref(pref, '') - ).unwrap()) + Services.prefs.getStringPref(pref, ''), + ).unwrap()), ) Services.prefs.addObserver(pref, observer) diff --git a/src/content/browser/components/toolbar/HamburgerMenu.svelte b/src/content/browser/components/toolbar/HamburgerMenu.svelte index bd7f829..a1b3f0b 100644 --- a/src/content/browser/components/toolbar/HamburgerMenu.svelte +++ b/src/content/browser/components/toolbar/HamburgerMenu.svelte @@ -28,14 +28,14 @@
Settings Bookmarks @@ -43,7 +43,9 @@ openTab( - resource.NetUtil.newURI('chrome://browser/content/credits/index.html') + resource.NetUtil.newURI( + 'chrome://browser/content/credits/index.html', + ), )} > Credits diff --git a/src/content/browser/components/toolbar/omnibox/Omnibox.svelte b/src/content/browser/components/toolbar/omnibox/Omnibox.svelte index 7e00332..c1ff56d 100644 --- a/src/content/browser/components/toolbar/omnibox/Omnibox.svelte +++ b/src/content/browser/components/toolbar/omnibox/Omnibox.svelte @@ -20,6 +20,15 @@ $: uri = tab.uri + async function generateSuggestions() { + const { suggestions: suggestionsMethod } = await suggestionsModule + suggestions = await suggestionsMethod(inputContent) + selectedSuggestion = Math.max( + Math.min(selectedSuggestion, suggestions.length - 1), + 0, + ) + } + const unbindedSetInputContent = (value: string) => { inputContent = value if (tab.tabJustOpened && inputElement) { @@ -48,19 +57,22 @@ aria-owns="omnibox__suggestions-list" bind:this={inputElement} bind:value={inputContent} - on:focusin={() => (showFocus = true)} + on:focusin={() => { + showFocus = true + generateSuggestions() + }} on:blur|capture={() => setTimeout(() => (showFocus = false) && (suggestions = []), 100)} on:keyup={async (e) => { if (e.key === 'Enter') return tab.goToUri( - resource.NetUtil.newURI(suggestions[selectedSuggestion].url) + resource.NetUtil.newURI(suggestions[selectedSuggestion].url), ) if (e.key === 'ArrowDown') { e.preventDefault() selectedSuggestion = Math.min( selectedSuggestion + 1, - suggestions.length - 1 + suggestions.length - 1, ) return } @@ -70,12 +82,7 @@ return } - const { suggestions: suggestionsMethod } = await suggestionsModule - suggestions = await suggestionsMethod(inputContent) - selectedSuggestion = Math.max( - Math.min(selectedSuggestion, suggestions.length - 1), - 0 - ) + await generateSuggestions() }} /> diff --git a/src/content/credits/Credits.svelte b/src/content/credits/Credits.svelte index 8fd4f63..01342f1 100644 --- a/src/content/credits/Credits.svelte +++ b/src/content/credits/Credits.svelte @@ -16,7 +16,7 @@ licenseText: string }[] > = fetch('chrome://browser/content/oss-licenses.json').then((res) => - res.json() + res.json(), ) diff --git a/src/content/settings/Settings.svelte b/src/content/settings/Settings.svelte index fef96a0..347aef1 100644 --- a/src/content/settings/Settings.svelte +++ b/src/content/settings/Settings.svelte @@ -16,7 +16,7 @@ let sidebarItems: SidebarItemData[] = [] const searchEngines: Promise = import('../shared/search/engine').then( - (search) => search.searchEngineService.getSearchEngines() + (search) => search.searchEngineService.getSearchEngines(), ) diff --git a/src/content/settings/components/Category.svelte b/src/content/settings/components/Category.svelte index 6b0c5cd..d4fbafc 100644 --- a/src/content/settings/components/Category.svelte +++ b/src/content/settings/components/Category.svelte @@ -17,7 +17,7 @@ return () => (sidebarItems = sidebarItems.filter( - (item) => item.counter != sidebarItem.counter + (item) => item.counter != sidebarItem.counter, )) }) diff --git a/src/content/shared/components/FancySelect.svelte b/src/content/shared/components/FancySelect.svelte index 413cf72..4e96850 100644 --- a/src/content/shared/components/FancySelect.svelte +++ b/src/content/shared/components/FancySelect.svelte @@ -13,8 +13,8 @@ onMount( () => (menulist.selectedIndex = items.findIndex( - (item) => item.value == selected - )) + (item) => item.value == selected, + )), ) $: menulist && (menulist.selectedIndex = items.findIndex((item) => item.value == selected))