Skip to content

Commit

Permalink
🐛 Generate suggestions on focus
Browse files Browse the repository at this point in the history
  • Loading branch information
trickypr committed Nov 14, 2023
1 parent ebf000b commit c022766
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion src/content/browser/Browser.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
</script>

Expand Down
6 changes: 3 additions & 3 deletions src/content/browser/components/keybindings/Keybinding.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions src/content/browser/components/toolbar/HamburgerMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,24 @@
<div class="panel__container">
<HamburgerMenuItem
on:click={openDialogWindowAction(
'chrome://browser/content/settings/index.html'
'chrome://browser/content/settings/index.html',
)}
>
Settings
</HamburgerMenuItem>
<HamburgerMenuItem
on:click={openDialogWindowAction(
'chrome://browser/content/bookmarks/index.html'
'chrome://browser/content/bookmarks/index.html',
)}
>
Bookmarks
</HamburgerMenuItem>
<HamburgerMenuItem
on:click={() =>
openTab(
resource.NetUtil.newURI('chrome://browser/content/credits/index.html')
resource.NetUtil.newURI(
'chrome://browser/content/credits/index.html',
),
)}
>
Credits
Expand Down
25 changes: 16 additions & 9 deletions src/content/browser/components/toolbar/omnibox/Omnibox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand All @@ -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()
}}
/>

Expand Down
2 changes: 1 addition & 1 deletion src/content/credits/Credits.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
licenseText: string
}[]
> = fetch('chrome://browser/content/oss-licenses.json').then((res) =>
res.json()
res.json(),
)
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/content/settings/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
let sidebarItems: SidebarItemData[] = []
const searchEngines: Promise<any[]> = import('../shared/search/engine').then(
(search) => search.searchEngineService.getSearchEngines()
(search) => search.searchEngineService.getSearchEngines(),
)
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/content/settings/components/Category.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
return () =>
(sidebarItems = sidebarItems.filter(
(item) => item.counter != sidebarItem.counter
(item) => item.counter != sidebarItem.counter,
))
})
</script>
Expand Down
4 changes: 2 additions & 2 deletions src/content/shared/components/FancySelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit c022766

Please sign in to comment.