Fix custom assistant keyboard shortcut (#3598)

This commit is contained in:
Zeno Kapitein
2025-08-26 16:57:08 +02:00
committed by GitHub
parent 9251b33959
commit a8fca0e033
4 changed files with 28 additions and 14 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Fix custom assistant keyboard shortcut
@@ -46,17 +46,6 @@ export function AIChat(props: { trademark: boolean }) {
}
}, [chat.opened]);
useHotkeys(
'mod+i',
(e) => {
e.preventDefault();
chatController.open();
},
{
enableOnFormTags: true,
}
);
useHotkeys(
'esc',
() => {
@@ -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={
<div className="flex items-center gap-2">
{t(language, 'ai_chat_ask', assistant.label)}
<KeyboardShortcut keys={['mod', 'i']} className="border-tint-11 text-tint-1" />
{withShortcut ? (
<KeyboardShortcut
keys={['mod', 'i']}
className="border-tint-11 text-tint-1"
/>
) : null}
</div>
}
onClick={() => assistant.open()}
@@ -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) {
</Popover>
{assistants
.filter((assistant) => assistant.ui === true)
.map((assistant) => (
.map((assistant, index) => (
<AIChatButton
key={assistant.id}
assistant={assistant}
withShortcut={index === 0}
showLabel={
assistants.filter((assistant) => assistant.ui === true).length === 1 &&
style === CustomizationSearchStyle.Prominent