diff --git a/scripts/prepare.ts b/scripts/prepare.ts
index 95191dc..6eb3cf9 100644
--- a/scripts/prepare.ts
+++ b/scripts/prepare.ts
@@ -10,8 +10,6 @@ import { r, port, isDev, log, isFirefoxInArg } from './utils'
async function stubIndexHtml() {
const views = ['options', 'popup']
- console.log('here')
-
for (const view of views) {
await fs.ensureDir(r(`extension/dist/${view}`))
let data = await fs.readFile(r(`views/${view}/index.html`), 'utf-8')
diff --git a/src/components/autocomplete/autocomplete.tsx b/src/components/autocomplete/autocomplete.tsx
index 0fef5d5..d5ddb9a 100644
--- a/src/components/autocomplete/autocomplete.tsx
+++ b/src/components/autocomplete/autocomplete.tsx
@@ -7,7 +7,7 @@ import { Shortcuts } from '../shortcuts'
const style: { default: string; disabled: string; label: string } = {
label: `text-gray-700`,
disabled: `cursor-not-allowed`,
- default: `input input-bordered w-[600px] shadow-lg`,
+ default: `input input-bordered min-w-[600px] w-full shadow-lg`,
}
export const Autocomplete: FunctionComponent = () => {
@@ -20,6 +20,7 @@ export const Autocomplete: FunctionComponent = () => {
onKeyDown,
value,
onSuggestionClick,
+ onMouseover,
} = useAutocomplete()
const { mainCommand } = useCommand()
@@ -37,9 +38,11 @@ export const Autocomplete: FunctionComponent = () => {
name="search"
placeholder={`Search `}
/>
-
-
-
+ {mainCommand && !value && (
+
+
+
+ )}
{
value,
onSuggestionClick,
suggestions,
- onKeyDown,
+ onMouseover,
}}
/>
diff --git a/src/components/autocomplete/suggestions-item.tsx b/src/components/autocomplete/suggestions-item.tsx
index ef3fa78..ec85576 100644
--- a/src/components/autocomplete/suggestions-item.tsx
+++ b/src/components/autocomplete/suggestions-item.tsx
@@ -8,7 +8,13 @@ export const listItemType: {
<>
{suggestion.title} {': '}
- {suggestion.url}
+
+ {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
+ {/*@ts-ignore*/}
+ {suggestion?.url?.length >= 90
+ ? `${suggestion.url?.substring(0, 90)}...`
+ : suggestion.url}
+
>
),
history: ({ suggestion }) => (
@@ -16,6 +22,13 @@ export const listItemType: {
{suggestion.title} {': '}
{suggestion.url}
+
+ {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}
+ {/*@ts-ignore*/}
+ {suggestion?.url?.length >= 90
+ ? `${suggestion.url?.substring(0, 90)}...`
+ : suggestion.url}
+
>
),
key: ({ suggestion }) => (
@@ -27,20 +40,35 @@ export const listItemType: {
}
export const searchHelperText = {
- bookmark: (_: any, value: string) => (
+ bookmark: (value: string) => (
<>
@Bookmarks Search
- {` ${value ? value.substring(1) : ''}`}
+ {` ${value ? value.substring(1, 35) : ''}`}
+ {value?.length > 35 ? '...' : ''}
>
),
- history: (_: any, value: string) => (
- <>
+ history: (value: string) => (
+
#History Search
- {` ${value ? value.substring(1) : ''}`}
- >
+ {` ${value ? value.substring(1, 35) : ''}`}
+ {value?.length > 35 ? '...' : ''}
+
),
- key: (showSearchMessageUrl: any, value: string) =>
- !!showSearchMessageUrl && `${value} Search on ${showSearchMessageUrl}`,
+}
+
+export const searchHelperQueryString = (
+ showSearchMessageUrl: any,
+ value: string,
+) => {
+ return (
+ !!showSearchMessageUrl && (
+ <>
+ Search on{' '}
+ {showSearchMessageUrl}: {value.substring(0, 35)}
+ {value?.length > 35 ? '...' : ''}
+ >
+ )
+ )
}
diff --git a/src/components/autocomplete/suggestions.tsx b/src/components/autocomplete/suggestions.tsx
index 376eaa1..de6af88 100644
--- a/src/components/autocomplete/suggestions.tsx
+++ b/src/components/autocomplete/suggestions.tsx
@@ -2,13 +2,17 @@ import { DEFAULT_VALUES } from './search-handler'
import browser from 'webextension-polyfill'
import { FunctionComponent } from 'preact'
import { ISuperKeyOptional } from '../../types'
-import { listItemType, searchHelperText } from './suggestions-item'
+import {
+ listItemType,
+ searchHelperQueryString,
+ searchHelperText,
+} from './suggestions-item'
import { getSearchType } from './helpers'
const style = {
activeItem: 'bg-gray-800 text-white',
item: `px-4 py-3 focus text-sm text-gray-200 cursor-pointer hover:bg-gray-600`,
- list: `shadow-xl top-full left-0 right-0 border w-auto md:max-w-full overflow-y-auto max-h-80 mt-2 p-3 z-20`,
+ list: `shadow-xl top-full left-0 right-0 border w-auto md:max-w-full overflow-y-auto max-h-80 p-3 z-20`,
}
export interface ISuggestionsProps {
@@ -18,7 +22,7 @@ export interface ISuggestionsProps {
showSuggestions: boolean
value: string
onSuggestionClick: (keyItem: object | string) => void
- onKeyDown: any
+ onMouseover?: any
}
const Suggestions: FunctionComponent = ({
@@ -28,7 +32,7 @@ const Suggestions: FunctionComponent = ({
showSuggestions,
value,
onSuggestionClick,
- onKeyDown,
+ onMouseover,
}) => {
if (!showSuggestions || !value) return null
@@ -36,70 +40,75 @@ const Suggestions: FunctionComponent = ({
const keyToFind = suggestions.find(item => item?.key === keyFromValue)
const searchValue = keyToFind
? value.replace(`${keyToFind.key}${DEFAULT_VALUES.separator}`, '')
- : ''
+ : value
// No sub query found and matched with key with space, can trigger search query
- const showSearchMessageUrl: any =
- !filteredSuggestions.length && keyToFind?.queryUrl && keyToFind?.url
+ const showSearchMessageUrl: '' | undefined | string =
+ keyToFind?.queryUrl && keyToFind?.url
const searchType = getSearchType(value)
- const helperText = searchHelperText[searchType]?.(showSearchMessageUrl, value)
+ const helperText =
+ searchType !== 'key' && searchHelperText[searchType]?.(value)
+
+ const helperTextQueryString = searchHelperQueryString(
+ showSearchMessageUrl,
+ searchValue,
+ )
return (
- {showSearchMessageUrl ? (
-
-
-
- {searchValue.substring(0, 35)}
- {searchValue?.length > 35 ? '...' : ''}
- {' '}
- Search on {showSearchMessageUrl}
-
+ {!!helperText && (
+
onSuggestionClick(value)}
+ >
+ {helperText}
- ) : (
- ''
)}
- {filteredSuggestions.length ? (
-
- {!!helperText && (
- - onSuggestionClick(value)}
- >
- {helperText}
-
- )}
- {filteredSuggestions.map((suggestion, i) => {
- let className
- const index = i + 1
+ {filteredSuggestions.length || !!showSearchMessageUrl ? (
+ <>
+
+ {!!helperTextQueryString && (
+ - onMouseover(0)}
+ onClick={() => onSuggestionClick(value)}
+ >
+ {helperTextQueryString}
+
+ )}
+ {filteredSuggestions.map((suggestion, i) => {
+ let className
+ const index = i + 1
- if (index === activeSuggestion) {
- className = `${style.item} ${style.activeItem}`
- }
+ if (index === activeSuggestion) {
+ className = `${style.item} ${style.activeItem}`
+ }
- if (index !== activeSuggestion) {
- className = style.item
- }
+ if (index !== activeSuggestion) {
+ className = style.item
+ }
- const ItemByType = listItemType[suggestion.type || 'key'] || <>>
+ const ItemByType = listItemType[suggestion.type || 'key'] || <>>
- return (
- - onSuggestionClick(suggestion)}
- >
-
-
- )
- })}
-
+ return (
+ - onSuggestionClick(suggestion)}
+ onMouseOver={() => onMouseover(index)}
+ >
+
+
+ )
+ })}
+
+ >
) : (
No {searchType === 'key' ? 'suggestion' : searchType} available!
diff --git a/src/components/autocomplete/use-autocomplete.tsx b/src/components/autocomplete/use-autocomplete.tsx
index 3a87c03..5f8da09 100644
--- a/src/components/autocomplete/use-autocomplete.tsx
+++ b/src/components/autocomplete/use-autocomplete.tsx
@@ -168,7 +168,16 @@ export const useAutocomplete = () => {
const keyCode: string = e.code
const { value } = e.target as HTMLInputElement
- keyBoardEvents[keyCode]?.(value)
+ const keyBoardEvent = keyBoardEvents[keyCode]
+
+ if (keyBoardEvent) {
+ e?.preventDefault()
+ keyBoardEvent?.(value)
+ }
+ }
+
+ const onMouseover = (index: number) => {
+ setActiveSuggestion(index)
}
return {
@@ -180,5 +189,6 @@ export const useAutocomplete = () => {
onKeyDown,
onSuggestionClick,
value,
+ onMouseover,
}
}