diff --git a/.changeset/nasty-drinks-smell.md b/.changeset/nasty-drinks-smell.md new file mode 100644 index 000000000..740414ed9 --- /dev/null +++ b/.changeset/nasty-drinks-smell.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Fix custom assistant keyboard shortcut diff --git a/packages/gitbook/src/components/AIChat/AIChat.tsx b/packages/gitbook/src/components/AIChat/AIChat.tsx index 3192636f6..325c19416 100644 --- a/packages/gitbook/src/components/AIChat/AIChat.tsx +++ b/packages/gitbook/src/components/AIChat/AIChat.tsx @@ -46,17 +46,6 @@ export function AIChat(props: { trademark: boolean }) { } }, [chat.opened]); - useHotkeys( - 'mod+i', - (e) => { - e.preventDefault(); - chatController.open(); - }, - { - enableOnFormTags: true, - } - ); - useHotkeys( 'esc', () => { diff --git a/packages/gitbook/src/components/AIChat/AIChatButton.tsx b/packages/gitbook/src/components/AIChat/AIChatButton.tsx index e7d7ba4c7..733a3d23e 100644 --- a/packages/gitbook/src/components/AIChat/AIChatButton.tsx +++ b/packages/gitbook/src/components/AIChat/AIChatButton.tsx @@ -12,8 +12,9 @@ import { KeyboardShortcut } from '../primitives/KeyboardShortcut'; export function AIChatButton(props: { assistant: Assistant; showLabel?: boolean; + withShortcut?: boolean; }) { - const { assistant, showLabel = true } = props; + const { assistant, showLabel = true, withShortcut = true } = props; const language = useLanguage(); return ( @@ -27,7 +28,12 @@ export function AIChatButton(props: { label={
{t(language, 'ai_chat_ask', assistant.label)} - + {withShortcut ? ( + + ) : null}
} onClick={() => assistant.open()} diff --git a/packages/gitbook/src/components/Search/SearchContainer.tsx b/packages/gitbook/src/components/Search/SearchContainer.tsx index 1a28faf25..3e5e5e610 100644 --- a/packages/gitbook/src/components/Search/SearchContainer.tsx +++ b/packages/gitbook/src/components/Search/SearchContainer.tsx @@ -88,6 +88,19 @@ export function SearchContainer(props: SearchContainerProps) { } ); + useHotkeys( + 'mod+i', + (e) => { + e.preventDefault(); + if (assistants) { + assistants[0]?.open(); + } + }, + { + enableOnFormTags: true, + } + ); + const onOpen = React.useCallback(() => { if (state?.open) { return; @@ -211,10 +224,11 @@ export function SearchContainer(props: SearchContainerProps) { {assistants .filter((assistant) => assistant.ui === true) - .map((assistant) => ( + .map((assistant, index) => ( assistant.ui === true).length === 1 && style === CustomizationSearchStyle.Prominent