From 9cad6a60c0f9f986fd35cc4c3d56d5ba472dc99f Mon Sep 17 00:00:00 2001 From: angelplusultra Date: Thu, 18 Sep 2025 14:42:47 -0700 Subject: [PATCH 1/6] Add functionality for slash command selection via keydown event --- .../SlashCommands/SlashPresets/index.jsx | 51 ++++++++++++--- .../PromptInput/SlashCommands/index.jsx | 16 ++++- .../PromptInput/SlashCommands/reset.jsx | 33 +++++++++- .../ChatContainer/PromptInput/index.jsx | 63 ++++++++++++++++--- 4 files changed, 144 insertions(+), 19 deletions(-) diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/index.jsx index d38378536ab..12126ed970e 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/PromptInput/SlashCommands/SlashPresets/index.jsx @@ -11,7 +11,12 @@ import { useTranslation } from "react-i18next"; import PublishEntityModal from "@/components/CommunityHub/PublishEntityModal"; export const CMD_REGEX = new RegExp(/[^a-zA-Z0-9_-]/g); -export default function SlashPresets({ setShowing, sendCommand, promptRef }) { +export default function SlashPresets({ + setShowing, + sendCommand, + promptRef, + highlightedSlashCommand, +}) { const { t } = useTranslation(); const isActiveAgentSession = useIsAgentSessionActive(); const { @@ -38,6 +43,37 @@ export default function SlashPresets({ setShowing, sendCommand, promptRef }) { fetchPresets(); }, []); + useEffect(() => { + const handleSelectHighlighted = (event) => { + const { highlightedIndex } = event.detail; + if (highlightedIndex === 0) { + // Reset command is selected + return; + } + + // Check if it's a preset selection (index 1 and above) + const presetIndex = highlightedIndex - 1; + if (presetIndex >= 0 && presetIndex < presets.length) { + const preset = presets[presetIndex]; + setShowing(false); + sendCommand({ text: `${preset.command} ` }); + promptRef?.current?.focus(); + } + }; + + window.addEventListener( + "selectHighlightedSlashCommand", + handleSelectHighlighted + ); + + return () => { + window.removeEventListener( + "selectHighlightedSlashCommand", + handleSelectHighlighted + ); + }; + }, [presets, setShowing, sendCommand, promptRef]); + /* * @checklist-item * If the URL has the slash-commands param, open the add modal for the user @@ -49,7 +85,7 @@ export default function SlashPresets({ setShowing, sendCommand, promptRef }) { !isAddModalOpen ) openAddModal(); - }, []); + }, [isAddModalOpen, openAddModal, searchParams]); if (isActiveAgentSession) return null; @@ -60,7 +96,7 @@ export default function SlashPresets({ setShowing, sendCommand, promptRef }) { const handleSavePreset = async (preset) => { const { error } = await System.createSlashCommandPreset(preset); - if (!!error) { + if (error) { showToast(error, "error"); return false; } @@ -81,7 +117,7 @@ export default function SlashPresets({ setShowing, sendCommand, promptRef }) { updatedPreset ); - if (!!error) { + if (error) { showToast(error, "error"); return; } @@ -113,10 +149,11 @@ export default function SlashPresets({ setShowing, sendCommand, promptRef }) { return ( <> - {presets.map((preset) => ( + {presets.map((preset, index) => ( { setShowing(false); sendCommand({ text: `${preset.command} ` }); @@ -161,7 +198,7 @@ export default function SlashPresets({ setShowing, sendCommand, promptRef }) { ); } -function PresetItem({ preset, onUse, onEdit, onPublish }) { +function PresetItem({ preset, onUse, onEdit, onPublish, highlighted }) { const [showMenu, setShowMenu] = useState(false); const menuRef = useRef(null); const menuButtonRef = useRef(null); @@ -187,7 +224,7 @@ function PresetItem({ preset, onUse, onEdit, onPublish }) { return (