Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
'use client';
|
|
|
|
|
|
2024-11-24 21:58:05 +00:00
|
|
|
import { useClickListener } from "@/hooks/useClickListener";
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
import { useTailwind } from "@/hooks/useTailwind";
|
2024-11-24 21:58:05 +00:00
|
|
|
import { SearchQueryParams } from "@/lib/types";
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
import { cn, createPathWithQueryParams } from "@/lib/utils";
|
|
|
|
|
import {
|
|
|
|
|
cursorCharLeft,
|
|
|
|
|
cursorCharRight,
|
|
|
|
|
cursorDocEnd,
|
|
|
|
|
cursorDocStart,
|
|
|
|
|
cursorLineBoundaryBackward,
|
|
|
|
|
cursorLineBoundaryForward,
|
|
|
|
|
deleteCharBackward,
|
|
|
|
|
deleteCharForward,
|
|
|
|
|
deleteGroupBackward,
|
|
|
|
|
deleteGroupForward,
|
|
|
|
|
deleteLineBoundaryBackward,
|
|
|
|
|
deleteLineBoundaryForward,
|
|
|
|
|
history,
|
|
|
|
|
historyKeymap,
|
|
|
|
|
selectAll,
|
|
|
|
|
selectCharLeft,
|
|
|
|
|
selectCharRight,
|
|
|
|
|
selectDocEnd,
|
|
|
|
|
selectDocStart,
|
|
|
|
|
selectLineBoundaryBackward,
|
|
|
|
|
selectLineBoundaryForward
|
|
|
|
|
} from "@codemirror/commands";
|
|
|
|
|
import { tags as t } from '@lezer/highlight';
|
|
|
|
|
import { createTheme } from '@uiw/codemirror-themes';
|
|
|
|
|
import CodeMirror, { Annotation, EditorView, KeyBinding, keymap, ReactCodeMirrorRef } from "@uiw/react-codemirror";
|
|
|
|
|
import { cva } from "class-variance-authority";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
2024-11-29 18:42:08 +00:00
|
|
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
import { useHotkeys } from 'react-hotkeys-hook';
|
2024-11-29 18:42:08 +00:00
|
|
|
import { SearchSuggestionsBox } from "./searchSuggestionsBox";
|
2024-11-24 21:58:05 +00:00
|
|
|
import { useSuggestionsData } from "./useSuggestionsData";
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
import { zoekt } from "./zoektLanguageExtension";
|
2024-11-29 18:42:08 +00:00
|
|
|
import { CounterClockwiseClockIcon } from "@radix-ui/react-icons";
|
|
|
|
|
import { useSuggestionModeAndQuery } from "./useSuggestionModeAndQuery";
|
|
|
|
|
import { Separator } from "@/components/ui/separator";
|
|
|
|
|
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
|
|
|
|
|
import { Toggle } from "@/components/ui/toggle";
|
2025-01-17 22:12:43 +00:00
|
|
|
import { KeyboardShortcutHint } from "../keyboardShortcutHint";
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
|
|
|
|
|
interface SearchBarProps {
|
|
|
|
|
className?: string;
|
|
|
|
|
size?: "default" | "sm";
|
|
|
|
|
defaultQuery?: string;
|
|
|
|
|
autoFocus?: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const searchBarKeymap: readonly KeyBinding[] = ([
|
|
|
|
|
{ key: "ArrowLeft", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true },
|
|
|
|
|
{ key: "ArrowRight", run: cursorCharRight, shift: selectCharRight, preventDefault: true },
|
|
|
|
|
|
|
|
|
|
{ key: "Home", run: cursorLineBoundaryBackward, shift: selectLineBoundaryBackward, preventDefault: true },
|
|
|
|
|
{ key: "Mod-Home", run: cursorDocStart, shift: selectDocStart },
|
|
|
|
|
|
|
|
|
|
{ key: "End", run: cursorLineBoundaryForward, shift: selectLineBoundaryForward, preventDefault: true },
|
|
|
|
|
{ key: "Mod-End", run: cursorDocEnd, shift: selectDocEnd },
|
|
|
|
|
|
|
|
|
|
{ key: "Mod-a", run: selectAll },
|
|
|
|
|
|
|
|
|
|
{ key: "Backspace", run: deleteCharBackward, shift: deleteCharBackward },
|
|
|
|
|
{ key: "Delete", run: deleteCharForward },
|
|
|
|
|
{ key: "Mod-Backspace", mac: "Alt-Backspace", run: deleteGroupBackward },
|
|
|
|
|
{ key: "Mod-Delete", mac: "Alt-Delete", run: deleteGroupForward },
|
|
|
|
|
{ mac: "Mod-Backspace", run: deleteLineBoundaryBackward },
|
|
|
|
|
{ mac: "Mod-Delete", run: deleteLineBoundaryForward }
|
|
|
|
|
] as KeyBinding[]).concat(historyKeymap);
|
|
|
|
|
|
|
|
|
|
const searchBarContainerVariants = cva(
|
2025-01-17 22:12:43 +00:00
|
|
|
"search-bar-container flex items-center justify-center py-0.5 px-2 border rounded-md relative",
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
{
|
|
|
|
|
variants: {
|
|
|
|
|
size: {
|
|
|
|
|
default: "h-10",
|
|
|
|
|
sm: "h-8"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
defaultVariants: {
|
|
|
|
|
size: "default",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const SearchBar = ({
|
|
|
|
|
className,
|
|
|
|
|
size,
|
|
|
|
|
defaultQuery,
|
|
|
|
|
autoFocus,
|
|
|
|
|
}: SearchBarProps) => {
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const tailwind = useTailwind();
|
|
|
|
|
const suggestionBoxRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const editorRef = useRef<ReactCodeMirrorRef>(null);
|
|
|
|
|
const [cursorPosition, setCursorPosition] = useState(0);
|
2024-11-29 18:42:08 +00:00
|
|
|
const [isSuggestionsEnabled, setIsSuggestionsEnabled] = useState(false);
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
const [isSuggestionsBoxFocused, setIsSuggestionsBoxFocused] = useState(false);
|
2024-11-29 18:42:08 +00:00
|
|
|
const [isHistorySearchEnabled, setIsHistorySearchEnabled] = useState(false);
|
|
|
|
|
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
const focusEditor = useCallback(() => editorRef.current?.view?.focus(), []);
|
|
|
|
|
const focusSuggestionsBox = useCallback(() => suggestionBoxRef.current?.focus(), []);
|
|
|
|
|
|
|
|
|
|
const [_query, setQuery] = useState(defaultQuery ?? "");
|
|
|
|
|
const query = useMemo(() => {
|
|
|
|
|
// Replace any newlines with spaces to handle
|
|
|
|
|
// copy & pasting text with newlines.
|
|
|
|
|
return _query.replaceAll(/\n/g, " ");
|
|
|
|
|
}, [_query]);
|
|
|
|
|
|
2024-11-29 18:42:08 +00:00
|
|
|
// When the user navigates backwards/forwards while on the
|
|
|
|
|
// search page (causing the `query` search param to change),
|
|
|
|
|
// we want to update what query is displayed in the search bar.
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (defaultQuery) {
|
|
|
|
|
setQuery(defaultQuery);
|
|
|
|
|
}
|
|
|
|
|
}, [defaultQuery])
|
|
|
|
|
|
|
|
|
|
const { suggestionMode, suggestionQuery } = useSuggestionModeAndQuery({
|
|
|
|
|
isSuggestionsEnabled,
|
|
|
|
|
isHistorySearchEnabled,
|
|
|
|
|
cursorPosition,
|
|
|
|
|
query,
|
|
|
|
|
});
|
|
|
|
|
|
2024-11-24 21:58:05 +00:00
|
|
|
const suggestionData = useSuggestionsData({
|
|
|
|
|
suggestionMode,
|
|
|
|
|
suggestionQuery,
|
|
|
|
|
});
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
|
|
|
|
|
const theme = useMemo(() => {
|
|
|
|
|
return createTheme({
|
|
|
|
|
theme: 'light',
|
|
|
|
|
settings: {
|
|
|
|
|
background: tailwind.theme.colors.background,
|
|
|
|
|
foreground: tailwind.theme.colors.foreground,
|
|
|
|
|
caret: '#AEAFAD',
|
|
|
|
|
},
|
|
|
|
|
styles: [
|
|
|
|
|
{
|
|
|
|
|
tag: t.keyword,
|
|
|
|
|
color: tailwind.theme.colors.highlight,
|
|
|
|
|
},
|
2024-12-09 18:46:53 +00:00
|
|
|
{
|
|
|
|
|
tag: t.string,
|
|
|
|
|
color: '#2aa198',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
tag: t.operator,
|
|
|
|
|
color: '#d33682',
|
|
|
|
|
},
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
{
|
|
|
|
|
tag: t.paren,
|
|
|
|
|
color: tailwind.theme.colors.highlight,
|
2024-12-09 18:46:53 +00:00
|
|
|
},
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
],
|
|
|
|
|
});
|
|
|
|
|
}, [tailwind]);
|
|
|
|
|
|
|
|
|
|
const extensions = useMemo(() => {
|
|
|
|
|
return [
|
|
|
|
|
keymap.of(searchBarKeymap),
|
|
|
|
|
history(),
|
|
|
|
|
zoekt(),
|
|
|
|
|
EditorView.updateListener.of(update => {
|
|
|
|
|
if (update.selectionSet) {
|
|
|
|
|
const selection = update.state.selection.main;
|
|
|
|
|
if (selection.empty) {
|
|
|
|
|
setCursorPosition(selection.anchor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
];
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
// Hotkey to focus the search bar.
|
|
|
|
|
useHotkeys('/', (event) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
focusEditor();
|
2024-11-29 18:42:08 +00:00
|
|
|
setIsSuggestionsEnabled(true);
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
if (editorRef.current?.view) {
|
|
|
|
|
cursorDocEnd({
|
|
|
|
|
state: editorRef.current.view.state,
|
|
|
|
|
dispatch: editorRef.current.view.dispatch,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Collapse the suggestions box if the user clicks outside of the search bar container.
|
|
|
|
|
useClickListener('.search-bar-container', (isElementClicked) => {
|
|
|
|
|
if (!isElementClicked) {
|
2024-11-29 18:42:08 +00:00
|
|
|
setIsSuggestionsEnabled(false);
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
} else {
|
2024-11-29 18:42:08 +00:00
|
|
|
setIsSuggestionsEnabled(true);
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2024-11-29 18:42:08 +00:00
|
|
|
const onSubmit = useCallback((query: string) => {
|
|
|
|
|
setIsSuggestionsEnabled(false);
|
|
|
|
|
setIsHistorySearchEnabled(false);
|
|
|
|
|
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
const url = createPathWithQueryParams('/search',
|
|
|
|
|
[SearchQueryParams.query, query],
|
2024-11-29 18:42:08 +00:00
|
|
|
);
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
router.push(url);
|
2024-11-29 18:42:08 +00:00
|
|
|
}, [router]);
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className={cn(searchBarContainerVariants({ size, className }))}
|
|
|
|
|
onKeyDown={(e) => {
|
|
|
|
|
if (e.key === 'Enter') {
|
|
|
|
|
e.preventDefault();
|
2024-11-29 18:42:08 +00:00
|
|
|
setIsSuggestionsEnabled(false);
|
|
|
|
|
onSubmit(query);
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.key === 'Escape') {
|
|
|
|
|
e.preventDefault();
|
2024-11-29 18:42:08 +00:00
|
|
|
setIsSuggestionsEnabled(false);
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.key === 'ArrowDown') {
|
|
|
|
|
e.preventDefault();
|
2024-11-29 18:42:08 +00:00
|
|
|
setIsSuggestionsEnabled(true);
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
focusSuggestionsBox();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.key === 'ArrowUp') {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
>
|
2024-11-29 18:42:08 +00:00
|
|
|
<SearchHistoryButton
|
|
|
|
|
isToggled={isHistorySearchEnabled}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setQuery("");
|
|
|
|
|
setIsHistorySearchEnabled(!isHistorySearchEnabled);
|
|
|
|
|
setIsSuggestionsEnabled(true);
|
|
|
|
|
focusEditor();
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Separator
|
|
|
|
|
className="mx-1 h-6"
|
|
|
|
|
orientation="vertical"
|
|
|
|
|
/>
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
<CodeMirror
|
|
|
|
|
ref={editorRef}
|
|
|
|
|
className="overflow-x-auto scrollbar-hide w-full"
|
2024-11-29 18:42:08 +00:00
|
|
|
placeholder={isHistorySearchEnabled ? "Filter history..." : "Search..."}
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
value={query}
|
|
|
|
|
onChange={(value) => {
|
|
|
|
|
setQuery(value);
|
|
|
|
|
// Whenever the user types, we want to re-enable
|
|
|
|
|
// the suggestions box.
|
2024-11-29 18:42:08 +00:00
|
|
|
setIsSuggestionsEnabled(true);
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
}}
|
|
|
|
|
theme={theme}
|
|
|
|
|
basicSetup={false}
|
|
|
|
|
extensions={extensions}
|
|
|
|
|
indentWithTab={false}
|
|
|
|
|
autoFocus={autoFocus ?? false}
|
|
|
|
|
/>
|
2025-01-17 22:12:43 +00:00
|
|
|
<KeyboardShortcutHint shortcut="/" />
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
<SearchSuggestionsBox
|
|
|
|
|
ref={suggestionBoxRef}
|
|
|
|
|
query={query}
|
2024-11-29 18:42:08 +00:00
|
|
|
suggestionQuery={suggestionQuery}
|
|
|
|
|
suggestionMode={suggestionMode}
|
|
|
|
|
onCompletion={(newQuery: string, newCursorPosition: number, autoSubmit = false) => {
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
setQuery(newQuery);
|
|
|
|
|
|
|
|
|
|
// Move the cursor to it's new position.
|
|
|
|
|
// @note : normally, react-codemirror handles syncing `query`
|
|
|
|
|
// and the document state, but this happens on re-render. Since
|
|
|
|
|
// we want to move the cursor before the component re-renders,
|
|
|
|
|
// we manually update the document state inline.
|
|
|
|
|
editorRef.current?.view?.dispatch({
|
|
|
|
|
changes: { from: 0, to: query.length, insert: newQuery },
|
|
|
|
|
annotations: [Annotation.define<boolean>().of(true)],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
editorRef.current?.view?.dispatch({
|
|
|
|
|
selection: { anchor: newCursorPosition, head: newCursorPosition },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Re-focus the editor since suggestions cause focus to be lost (both click & keyboard)
|
|
|
|
|
editorRef.current?.view?.focus();
|
2024-11-29 18:42:08 +00:00
|
|
|
|
|
|
|
|
if (autoSubmit) {
|
|
|
|
|
onSubmit(newQuery);
|
|
|
|
|
}
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
}}
|
2024-11-29 18:42:08 +00:00
|
|
|
isEnabled={isSuggestionsEnabled}
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
onReturnFocus={() => {
|
|
|
|
|
focusEditor();
|
|
|
|
|
}}
|
|
|
|
|
isFocused={isSuggestionsBoxFocused}
|
|
|
|
|
onFocus={() => {
|
|
|
|
|
setIsSuggestionsBoxFocused(document.activeElement === suggestionBoxRef.current);
|
|
|
|
|
}}
|
|
|
|
|
onBlur={() => {
|
|
|
|
|
setIsSuggestionsBoxFocused(document.activeElement === suggestionBoxRef.current);
|
|
|
|
|
}}
|
|
|
|
|
cursorPosition={cursorPosition}
|
2024-11-28 21:26:27 +00:00
|
|
|
{...suggestionData}
|
Search suggestions (#85)
The motivation for building search suggestions is two-fold: (1) to make the zoekt query language more approachable by presenting all available options to the user, and (2) make it easier for power-users to craft complex queries.
The meat-n-potatoes of this change are concentrated in searchBar.tsx and searchSuggestionBox.tsx. The suggestions box works by maintaining a state-machine of "modes". By default, the box is in the refine mode, where suggestions for different prefixes (e.g., repo:, lang:, etc.) are suggested to the user. When one of these prefixes is matched, the state-machine transitions to the corresponding mode (e.g., repository, language, etc.) and surfaces suggestions for that mode (if any).
The query is split up into parts by spaces " " (e.g., 'test repo:hello' -> ['test', 'repo:hello']). See splitQuery. The part that has the cursor over it is considered the active part. We evaluate which mode the state machine is in based on the active part. When a suggestion is clicked, we only modify the active part of the query.
Three modes are currently missing suggestion data: file (file names), revision (branch / tag names), and symbol (symbol names). In future PRs, we will need to introduce endpoints into the backend to allow the frontend to fetch this data and surface it as suggestions..
2024-11-23 02:50:13 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2024-11-29 18:42:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const SearchHistoryButton = ({
|
|
|
|
|
isToggled,
|
|
|
|
|
onClick,
|
|
|
|
|
}: {
|
|
|
|
|
isToggled: boolean,
|
|
|
|
|
onClick: () => void
|
|
|
|
|
}) => {
|
|
|
|
|
return (
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger
|
|
|
|
|
asChild={true}
|
|
|
|
|
>
|
|
|
|
|
{/* @see : https://github.com/shadcn-ui/ui/issues/1988#issuecomment-1980597269 */}
|
|
|
|
|
<div>
|
|
|
|
|
<Toggle
|
|
|
|
|
pressed={isToggled}
|
|
|
|
|
className="h-6 w-6 min-w-6 px-0 p-1 cursor-pointer"
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
>
|
|
|
|
|
<CounterClockwiseClockIcon />
|
|
|
|
|
</Toggle>
|
|
|
|
|
</div>
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent
|
|
|
|
|
side="bottom"
|
|
|
|
|
>
|
|
|
|
|
Search history
|
|
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)
|
2024-12-09 18:46:53 +00:00
|
|
|
}
|