Skip to content

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

Home end search fix (#3110)

Erik Tewsf7ce61b1b3e6
diff --git a/apps/web/components/dashboard/search/SearchInput.tsx b/apps/web/components/dashboard/search/SearchInput.tsx
index a09e635f..ed3aeb1e 100644
--- a/apps/web/components/dashboard/search/SearchInput.tsx
+++ b/apps/web/components/dashboard/search/SearchInput.tsx
@@ -77,7 +77,7 @@ function useFocusSearchOnKeyPress(
const SearchInput = React.forwardRef<
HTMLInputElement,
React.HTMLAttributes<HTMLInputElement> & { loading?: boolean }
->(({ className, ...props }, ref) => {
+>(({ className, onKeyDown, ...props }, ref) => {
const { t } = useTranslation();
const { semanticSearchEnabled } = useClientConfig().search;
const {
@@ -128,6 +128,20 @@ const SearchInput = React.forwardRef<
[debounceSearch],
);
+ const handleInputKeyDown = useCallback(
+ (e: React.KeyboardEvent<HTMLInputElement>) => {
+ // Let callers handle the event first, then apply our Home/End fix.
+ onKeyDown?.(e);
+ // cmdk's root handler prevents the default for Home/End to move the
+ // list selection. The search box is a text field, so let the browser
+ // move the caret (and handle shift-selection) instead.
+ if (e.key === "Home" || e.key === "End") {
+ e.stopPropagation();
+ }
+ },
+ [onKeyDown],
+ );
+
const {
suggestionGroups,
hasSuggestions,
@@ -250,6 +264,7 @@ const SearchInput = React.forwardRef<
className,
)}
{...props}
+ onKeyDown={handleInputKeyDown}
/>
</div>
</PopoverTrigger>