diff --git a/.continue/rules/use-tailwind-not-styled.md b/.continue/rules/use-tailwind-not-styled.md deleted file mode 100644 index 8a3ec0b3d..000000000 --- a/.continue/rules/use-tailwind-not-styled.md +++ /dev/null @@ -1,3 +0,0 @@ -Always use Tailwind classes, not styled components. - -If a component is using styled components, it should be converted to use Tailwind classes. diff --git a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx index a680fa201..776c0721b 100644 --- a/gui/src/components/ConversationStarters/ConversationStarterCards.tsx +++ b/gui/src/components/ConversationStarters/ConversationStarterCards.tsx @@ -1,9 +1,7 @@ import { SlashCommandDescription } from "core"; import { useState } from "react"; import { useBookmarkedSlashCommands } from "../../hooks/useBookmarkedSlashCommands"; -import { MAIN_EDITOR_INPUT_ID } from "../../pages/gui/Chat"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { setNewestToolbarPreviewForInput } from "../../redux/slices/sessionSlice"; import { useMainEditor } from "../mainInput/TipTapEditor"; import { ConversationStarterCard } from "./ConversationStarterCard"; @@ -26,14 +24,7 @@ export function ConversationStarterCards() { ); function onClick(command: SlashCommandDescription) { - dispatch( - setNewestToolbarPreviewForInput({ - inputId: MAIN_EDITOR_INPUT_ID, - contextItemId: command.name, - }), - ); - - mainEditor?.commands.insertSlashCommand(command); + mainEditor?.commands.insertPrompt(command); } if (bookmarkedSlashCommands.length === 0) { diff --git a/gui/src/components/mainInput/Lump/LumpContext.tsx b/gui/src/components/mainInput/Lump/LumpContext.tsx new file mode 100644 index 000000000..4e93777ea --- /dev/null +++ b/gui/src/components/mainInput/Lump/LumpContext.tsx @@ -0,0 +1,51 @@ +/** + * Provides context for controlling the Lump component's visibility state + */ +import { createContext, ReactNode, useContext } from "react"; + +interface LumpContextType { + isLumpVisible: boolean; + selectedSection: string | null; + hideLump: () => void; + setSelectedSection: (section: string | null) => void; +} + +const LumpContext = createContext(undefined); + +interface LumpProviderProps { + children: ReactNode; + isLumpVisible: boolean; + selectedSection: string | null; + hideLump: () => void; + setSelectedSection: (section: string | null) => void; +} + +/** + * Provider component that makes Lump state available to any child component + */ +export function LumpProvider({ + children, + isLumpVisible, + selectedSection, + hideLump, + setSelectedSection, +}: LumpProviderProps) { + return ( + + {children} + + ); +} + +/** + * Hook that lets any component access the Lump context + */ +export function useLump() { + const context = useContext(LumpContext); + if (context === undefined) { + throw new Error("useLump must be used within a LumpProvider"); + } + return context; +} diff --git a/gui/src/components/mainInput/Lump/index.tsx b/gui/src/components/mainInput/Lump/index.tsx index 57276ad56..df1875c86 100644 --- a/gui/src/components/mainInput/Lump/index.tsx +++ b/gui/src/components/mainInput/Lump/index.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useCallback, useState } from "react"; import styled from "styled-components"; import { defaultBorderRadius, @@ -6,6 +6,7 @@ import { vscInputBackground, } from "../.."; import { useAppSelector } from "../../../redux/hooks"; +import { LumpProvider } from "./LumpContext"; import { LumpToolbar } from "./LumpToolbar"; import { SelectedSection } from "./sections/SelectedSection"; @@ -30,64 +31,78 @@ const ContentDiv = styled.div<{ hasSection: boolean; isVisible: boolean }>` overflow-y: auto; `; +/** + * Main component that displays the toolbar and selected content section + */ export function Lump() { const [selectedSection, setSelectedSection] = useState(null); const [displayedSection, setDisplayedSection] = useState(null); const [isVisible, setIsVisible] = useState(false); const isStreaming = useAppSelector((state) => state.session.isStreaming); - useEffect(() => { - if (!selectedSection) { - return; - } - const handleKeyDown = (event: KeyboardEvent) => { - if (event.key === "Escape") { + // Handle keyboard escape + const handleKeyDown = useCallback( + (event: KeyboardEvent) => { + if (event.key === "Escape" && selectedSection) { setSelectedSection(null); } - }; - document.addEventListener("keydown", handleKeyDown); - return () => { - document.removeEventListener("keydown", handleKeyDown); - }; - }, [selectedSection]); + }, + [selectedSection], + ); - useEffect(() => { - if (isStreaming) { - setSelectedSection(null); - } - }, [isStreaming]); + // Function to hide the lump + const hideLump = useCallback(() => { + setSelectedSection(null); + }, []); - useEffect(() => { - if (selectedSection) { + // Reset when streaming starts + if (isStreaming && selectedSection) { + setSelectedSection(null); + } + + // Update displayedSection and visibility when selectedSection changes + if (selectedSection) { + if (displayedSection !== selectedSection || !isVisible) { setDisplayedSection(selectedSection); setIsVisible(true); - } else { - setIsVisible(false); - const timeout = setTimeout(() => { - setDisplayedSection(null); - }, 300); - return () => { - clearTimeout(timeout); - }; } - }, [selectedSection]); + } else if (isVisible) { + setIsVisible(false); + setTimeout(() => { + setDisplayedSection(null); + }, 300); + } + + // Set up keyboard listener + if (selectedSection) { + document.addEventListener("keydown", handleKeyDown); + } else { + document.removeEventListener("keydown", handleKeyDown); + } return ( - -
- + + +
+ - - - -
-
+ + + +
+
+ ); } diff --git a/gui/src/components/mainInput/Lump/sections/ExploreBlocksButton.tsx b/gui/src/components/mainInput/Lump/sections/ExploreBlocksButton.tsx index ad2212ac7..6885870df 100644 --- a/gui/src/components/mainInput/Lump/sections/ExploreBlocksButton.tsx +++ b/gui/src/components/mainInput/Lump/sections/ExploreBlocksButton.tsx @@ -50,7 +50,7 @@ export function ExploreBlocksButton(props: { blockType: string }) { return (
- {text} + + {text}
); diff --git a/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx b/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx index 6ad536809..1ff27c16c 100644 --- a/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/PromptsSection.tsx @@ -3,44 +3,70 @@ import { PencilIcon, } from "@heroicons/react/24/outline"; import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid"; +import { SlashCommandDescription } from "core"; import { useBookmarkedSlashCommands } from "../../../../hooks/useBookmarkedSlashCommands"; import { useAppSelector } from "../../../../redux/hooks"; import { fontSize } from "../../../../util"; +import { useMainEditor } from "../../TipTapEditor"; +import { useLump } from "../LumpContext"; import { ExploreBlocksButton } from "./ExploreBlocksButton"; interface PromptRowProps { - command: string; - description: string; + prompt: SlashCommandDescription; isBookmarked: boolean; setIsBookmarked: (isBookmarked: boolean) => void; onEdit?: () => void; } +/** + * Displays a single prompt row with bookmark and edit controls + */ function PromptRow({ - command, - description, + prompt, isBookmarked, setIsBookmarked, onEdit, }: PromptRowProps) { + const { mainEditor } = useMainEditor(); + const { hideLump } = useLump(); + + const handlePromptClick = (e: React.MouseEvent) => { + e.stopPropagation(); + mainEditor?.commands.insertPrompt(prompt); + hideLump(); + }; + + const handleBookmarkClick = (e: React.MouseEvent) => { + e.stopPropagation(); + setIsBookmarked(!isBookmarked); + }; + + const handleEditClick = (e: React.MouseEvent) => { + e.stopPropagation(); + if (onEdit) { + onEdit(); + } + }; + return (
- {command} - {description} + {prompt.name} + {prompt.description}
setIsBookmarked(!isBookmarked)} + onClick={handleBookmarkClick} className="cursor-pointer pt-0.5 text-gray-400 hover:brightness-125" > {isBookmarked ? ( @@ -54,8 +80,12 @@ function PromptRow({ ); } +/** + * Section that displays all available prompts with bookmarking functionality + */ export function PromptsSection() { const { isCommandBookmarked, toggleBookmark } = useBookmarkedSlashCommands(); + const slashCommands = useAppSelector( (state) => state.config.config.slashCommands ?? [], ); @@ -78,8 +108,7 @@ export function PromptsSection() { {sortedCommands.map((prompt) => ( toggleBookmark(prompt)} onEdit={() => handleEdit(prompt)} diff --git a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx index 4cb7b0051..43c338b49 100644 --- a/gui/src/components/mainInput/Lump/sections/RulesSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/RulesSection.tsx @@ -13,6 +13,7 @@ import { import { RootState } from "../../../../redux/store"; import { fontSize } from "../../../../util"; import HeaderButtonWithToolTip from "../../../gui/HeaderButtonWithToolTip"; +import { useLump } from "../LumpContext"; import { ExploreBlocksButton } from "./ExploreBlocksButton"; interface RuleCardProps { @@ -82,6 +83,7 @@ const RuleCard: React.FC = ({ index, rule, onClick, title }) => { export function RulesSection() { const ideMessenger = useContext(IdeMessengerContext); const { selectedProfile } = useAuth(); + const { hideLump } = useLump(); const rules = useSelector( (state: RootState) => state.config.config.rules ?? [], @@ -97,11 +99,13 @@ export function RulesSection() { })); }, [rules]); - const openUrl = (path: string) => + const openUrl = (path: string) => { ideMessenger.request("controlPlane/openUrl", { path, orgSlug: undefined, }); + hideLump(); + }; return (
@@ -113,11 +117,12 @@ export function RulesSection() { key={index} index={index} rule={rule.unrolledRule} - onClick={() => + onClick={() => { ideMessenger.post("config/openProfile", { profileId: undefined, - }) - } + }); + hideLump(); + }} title="Locally Defined Rule" /> ); @@ -158,6 +163,3 @@ export function RulesSection() {
); } -function useTypedDispatch() { - throw new Error("Function not implemented."); -} diff --git a/gui/src/components/mainInput/Lump/sections/docs/DocsIndexingStatus.tsx b/gui/src/components/mainInput/Lump/sections/docs/DocsIndexingStatus.tsx index 777d30e4e..9189a794c 100644 --- a/gui/src/components/mainInput/Lump/sections/docs/DocsIndexingStatus.tsx +++ b/gui/src/components/mainInput/Lump/sections/docs/DocsIndexingStatus.tsx @@ -12,6 +12,7 @@ import { import { fontSize } from "../../../../../util"; import ConfirmationDialog from "../../../../dialogs/ConfirmationDialog"; import EditBlockButton from "../../EditBlockButton"; +import { useLump } from "../../LumpContext"; import { StatusIndicator } from "./StatusIndicator"; interface IndexingStatusViewerProps { docConfig: SiteIndexingConfig; @@ -24,6 +25,7 @@ function DocsIndexingStatus({ }: IndexingStatusViewerProps) { const ideMessenger = useContext(IdeMessengerContext); const dispatch = useAppDispatch(); + const { hideLump } = useLump(); const status = useAppSelector( (store) => store.indexing.indexing.statuses[docConfig.startUrl], @@ -87,6 +89,7 @@ function DocsIndexingStatus({ onClick={() => { if (status?.url) { ideMessenger.post("openUrl", status.url); + hideLump(); } }} > diff --git a/gui/src/components/mainInput/Lump/sections/docs/DocsSection.tsx b/gui/src/components/mainInput/Lump/sections/docs/DocsSection.tsx index 27796aecb..cbe7e6e72 100644 --- a/gui/src/components/mainInput/Lump/sections/docs/DocsSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/docs/DocsSection.tsx @@ -14,7 +14,6 @@ function DocsIndexingStatuses() { (store) => store.indexing.indexing.statuses, ); const { selectedProfile } = useAuth(); - const mergedDocs = useMemo(() => { const parsed = selectedProfile?.rawYaml ? parseConfigYaml(selectedProfile?.rawYaml ?? "") diff --git a/gui/src/components/mainInput/TipTapEditor/components/ExpandableToolbarPreview.tsx b/gui/src/components/mainInput/TipTapEditor/components/ExpandableToolbarPreview.tsx index 9dd68df28..16e959ebb 100644 --- a/gui/src/components/mainInput/TipTapEditor/components/ExpandableToolbarPreview.tsx +++ b/gui/src/components/mainInput/TipTapEditor/components/ExpandableToolbarPreview.tsx @@ -102,6 +102,12 @@ export function ExpandableToolbarPreview(props: ExpandableToolbarPreviewProps) { ); const calculatedInitiallyHidden = useMemo(() => { + // If initiallyHidden is explicitly set to false, always start visible + if (props.initiallyHidden === false) { + return false; + } + + // Otherwise, use the inputId/itemId logic if (props.inputId && props.itemId) { return newestCodeblockForInputId !== props.itemId; } @@ -116,13 +122,19 @@ export function ExpandableToolbarPreview(props: ExpandableToolbarPreviewProps) { const [hidden, setHidden] = useState(calculatedInitiallyHidden); const [isExpanded, setIsExpanded] = useState(false); + // Track if user has manually toggled visibility + const [userToggled, setUserToggled] = useState(false); + const contentRef = useRef(null); const [contentDims, setContentDims] = useState({ width: 0, height: 0 }); useEffect(() => { - setHidden(calculatedInitiallyHidden); - }, [calculatedInitiallyHidden]); - + // Only update hidden state from props if user hasn't manually toggled + // or if initiallyHidden isn't explicitly set to false + if (!userToggled || props.initiallyHidden !== false) { + setHidden(calculatedInitiallyHidden); + } + }, [calculatedInitiallyHidden, userToggled, props.initiallyHidden]); useEffect(() => { const resizeObserver = new ResizeObserver(() => { setContentDims({ @@ -146,7 +158,7 @@ export function ExpandableToolbarPreview(props: ExpandableToolbarPreviewProps) { borderColor={ props.isSelected ? vscBadgeBackground : vscCommandCenterInactiveBorder } - className="find-widget-skip" + className="find-widget-skip !my-0" >
{ + setUserToggled(true); setHidden(!hidden); }} > diff --git a/gui/src/components/mainInput/TipTapEditor/components/NodeViewWrapper.tsx b/gui/src/components/mainInput/TipTapEditor/components/NodeViewWrapper.tsx index 1dc7ccd51..ac1a67836 100644 --- a/gui/src/components/mainInput/TipTapEditor/components/NodeViewWrapper.tsx +++ b/gui/src/components/mainInput/TipTapEditor/components/NodeViewWrapper.tsx @@ -16,7 +16,7 @@ export const NodeViewWrapper: React.FC = ({ const nodeViewWrapperTag: TiptapNodeViewWrapperProps["as"] = "p"; return ( - + {children} ); diff --git a/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlock.ts b/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlock.ts index 5cbe10767..b35a637ea 100644 --- a/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlock.ts +++ b/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlock.ts @@ -1,7 +1,8 @@ import { mergeAttributes, Node } from "@tiptap/core"; import { Node as ProseMirrorNode } from "@tiptap/pm/model"; import { ReactNodeViewRenderer } from "@tiptap/react"; -import { ContextItemWithId } from "core"; +import { ContextItemWithId, SlashCommandDescription } from "core"; +import { MAIN_EDITOR_INPUT_ID } from "../../../../../pages/gui/Chat"; import { PromptBlockPreview } from "./PromptBlockPreview"; export interface PromptBlockOptions { @@ -19,7 +20,7 @@ declare module "@tiptap/core" { /** * Insert a prompt block into the editor */ - insertPrompt: (item: ContextItemWithId, inputId: string) => ReturnType; + insertPrompt: (item: SlashCommandDescription) => ReturnType; /** * Clear all prompt blocks from the editor @@ -35,6 +36,7 @@ declare module "@tiptap/core" { export const PromptBlock = Node.create({ name: "prompt-block", group: "block", + content: "inline*", addOptions() { return { @@ -74,15 +76,28 @@ export const PromptBlock = Node.create({ addCommands() { return { insertPrompt: - (item: ContextItemWithId, inputId: string) => - ({ commands }) => { - return commands.insertContent({ - type: this.name, - attrs: { - item, - inputId, + (prompt: SlashCommandDescription) => + ({ chain }) => { + const item: ContextItemWithId = { + content: prompt.prompt ?? "", + name: prompt.name, + description: prompt.description, + id: { + providerTitle: "prompt", + itemId: prompt.name, }, - }); + }; + + return chain() + .insertContentAt(0, { + type: this.name, + attrs: { + item, + inputId: MAIN_EDITOR_INPUT_ID, + }, + }) + .focus("end") + .run(); }, // TODO: This could probably be greatly simplified with something along the lines of diff --git a/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlockPreview.tsx b/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlockPreview.tsx index 899cbdd37..8a1095d80 100644 --- a/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlockPreview.tsx +++ b/gui/src/components/mainInput/TipTapEditor/extensions/Prompt/PromptBlockPreview.tsx @@ -27,12 +27,13 @@ export const PromptBlockPreview = ({ }; const handleDelete = () => { - editor.commands.clearSlashCommand(); + editor.commands.clearPrompt(); }; return ( } diff --git a/gui/src/components/mainInput/TipTapEditor/extensions/SlashCommand.ts b/gui/src/components/mainInput/TipTapEditor/extensions/SlashCommand.ts index 4b5517c87..892d80355 100644 --- a/gui/src/components/mainInput/TipTapEditor/extensions/SlashCommand.ts +++ b/gui/src/components/mainInput/TipTapEditor/extensions/SlashCommand.ts @@ -1,191 +1,50 @@ // Adapted from SlashCommand extension (@tiptap/extension-mention/src/mention.ts) -import { mergeAttributes, Node } from "@tiptap/core"; -import Document from "@tiptap/extension-document"; -import Paragraph from "@tiptap/extension-paragraph"; -import { Node as ProseMirrorNode } from "@tiptap/pm/model"; +import { Node } from "@tiptap/core"; import { PluginKey } from "@tiptap/pm/state"; import Suggestion, { SuggestionOptions } from "@tiptap/suggestion"; -import { ContextItemWithId, SlashCommandDescription } from "core"; -import { MAIN_EDITOR_INPUT_ID } from "../../../../pages/gui/Chat"; import { ComboBoxItem } from "../../types"; -import { PromptBlock } from "./Prompt/PromptBlock"; export type SlashCommandOptions = { - HTMLAttributes: Record; - renderText: (props: { node: ProseMirrorNode }) => string; suggestion: Omit, "editor">; }; -declare module "@tiptap/core" { - interface Commands { - slashCommand: { - /** - * Insert a slash command and its associated prompt block - * @param command The slash command description - */ - insertSlashCommand: (command: SlashCommandDescription) => ReturnType; - - /** - * Clear the slash command content from the editor - */ - clearSlashCommand: () => ReturnType; - }; - } -} - export const SlashCommand = Node.create({ name: "slash-command", addOptions() { return { - HTMLAttributes: { - class: "mention", - }, - renderText({ node }) { - return node.attrs.label ?? node.attrs.id; - }, suggestion: { char: "/", pluginKey: new PluginKey(this.name), startOfLine: true, command: ({ editor, range, props }) => { - // increase range.to by one when the next node is of type "text" - // and starts with a space character - const nodeAfter = editor.view.state.selection.$to.nodeAfter; - const overrideSpace = nodeAfter?.text?.startsWith(" "); + // First delete the slash character and any text after it + editor.chain().focus().deleteRange(range).run(); - if (overrideSpace) { - range.to += 1; - } - - editor.commands.insertSlashCommand({ + editor.commands.insertPrompt({ name: props.title, description: props.description, prompt: props.content, }); - - window.getSelection()?.collapseToEnd(); - }, - allow: ({ state, range }) => { - const $from = state.doc.resolve(range.from); - const type = state.schema.nodes[this.name]; - const allow = !!$from.parent.type.contentMatch.matchType(type); - - return allow; }, }, }; }, group: "inline", - inline: true, - selectable: false, - atom: true, + // We don't need attributes since we won't be rendering any node addAttributes() { - return { - id: { - default: null, - parseHTML: (element) => element.getAttribute("data-id"), - renderHTML: (attributes) => { - if (!attributes.id) { - return {}; - } - - return { - "data-id": attributes.id, - }; - }, - }, - - label: { - default: null, - parseHTML: (element) => element.getAttribute("data-label"), - renderHTML: (attributes) => { - if (!attributes.label) { - return {}; - } - - return { - "data-label": attributes.label, - }; - }, - }, - }; + return {}; }, + // No need to parse HTML since we're not rendering anything parseHTML() { - return [ - { - tag: `span[data-type="${this.name}"]`, - }, - ]; - }, - - renderHTML({ node, HTMLAttributes }) { - return [ - "span", - mergeAttributes( - { "data-type": this.name }, - this.options.HTMLAttributes, - HTMLAttributes, - ), - this.options.renderText({ - node, - }), - ]; - }, - - addKeyboardShortcuts() { - return { - Backspace: () => { - // Get a reference to the editor - const editor = this.editor; - - // First try to find if we're at a slash command - const result = editor.commands.command(({ tr, state }) => { - let isSlashCommand = false; - const { selection } = state; - const { empty, anchor } = selection; - - if (!empty) { - return false; - } - - state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => { - if (node.type.name === this.name) { - isSlashCommand = true; - tr.insertText( - this.options.suggestion.char || "", - pos, - pos + node.nodeSize, - ); - - return false; - } - }); - - return isSlashCommand; - }); - - // If we found and processed a slash command, also call clearSlashCommand - // to remove the prompt block - if (result) { - // We need to do this with a small delay to ensure the transaction - // above completes first - setTimeout(() => { - editor.commands.clearSlashCommand(); - }, 0); - return true; - } - - return false; - }, - }; + return []; }, addProseMirrorPlugins() { @@ -196,90 +55,4 @@ export const SlashCommand = Node.create({ }), ]; }, - - addCommands() { - return { - insertSlashCommand: - ( - command: SlashCommandDescription, - inputId: string = MAIN_EDITOR_INPUT_ID, - ) => - ({ chain }) => { - if (!command.prompt) { - return false; - } - - const contextItem: ContextItemWithId = { - content: command.prompt, - name: command.name, - description: command.description || "", - id: { - providerTitle: "prompt", - itemId: command.name, - }, - }; - - // Right now this inserts at the beginning of the document, which removes codeblocks. - // This is the current behavior of slash commands, eg codeblocks aren't sent. - // Once this bug if fixed, we should instead insert prompt block at the beginning of the document - // without clearing the codeblocks. - return chain() - .setContent({ - type: Document.name, - content: [ - // First insert the prompt using the PromptExtension command - { - type: PromptBlock.name, - attrs: { - item: contextItem, - inputId, - }, - }, - // Add the paragraph with the slash command - { - type: Paragraph.name, - content: [ - { - type: this.name, - attrs: { - id: command.name, - label: command.name, - }, - }, - { - type: "text", - text: " ", - }, - ], - }, - ], - }) - .focus() - .run(); - }, - - clearSlashCommand: - () => - ({ editor }) => { - editor.commands.clearPrompt(); - - editor.commands.command(({ tr, state }) => { - let hasDeleted = false; - - // Find all slash command nodes in the document - state.doc.descendants((node, pos) => { - if (node.type.name === this.name) { - // Delete the node at the found position - tr.delete(pos, pos + node.nodeSize); - hasDeleted = true; - } - }); - - return hasDeleted; - }); - - return true; - }, - }; - }, }); diff --git a/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts b/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts index 69feed370..6e7808ba7 100644 --- a/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts +++ b/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts @@ -9,7 +9,7 @@ import { } from "../../../redux/slices/sessionSlice"; import { AppDispatch } from "../../../redux/store"; import { loadSession, saveCurrentSession } from "../../../redux/thunks/session"; -import { CodeBlock } from "./extensions"; +import { CodeBlock, PromptBlock } from "./extensions"; /** * Hook for setting up main editor specific webview listeners @@ -111,16 +111,20 @@ export function useMainEditorWebviewListeners({ let index = 0; for (const el of editor.getJSON()?.content ?? []) { + // Prevent exact duplicate code blocks if (el.attrs?.item?.name === contextItem.name) { - return; // Prevent exact duplicate code blocks + return; } - if (el.type === CodeBlock.name) { + + if (el.type === CodeBlock.name || el.type === PromptBlock.name) { index += 2; } else { break; } } + debugger; + editor .chain() .insertContentAt(index, { diff --git a/gui/src/components/mainInput/TipTapEditor/utils/getSuggestion.ts b/gui/src/components/mainInput/TipTapEditor/utils/getSuggestion.ts index 399701e9d..8c0613a4a 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/getSuggestion.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/getSuggestion.ts @@ -7,7 +7,6 @@ import { import { MutableRefObject } from "react"; import tippy from "tippy.js"; import { IIdeMessenger } from "../../../../context/IdeMessenger"; -import { setNewestToolbarPreviewForInput } from "../../../../redux/slices/sessionSlice"; import { AppDispatch } from "../../../../redux/store"; import AtMentionDropdown from "../../AtMentionDropdown"; import { ComboBoxItem, ComboBoxItemType, ComboBoxSubAction } from "../../types"; @@ -222,16 +221,7 @@ export function getSlashCommandDropdownOptions( label: provider.title, type: (provider.type ?? SlashCommand.name) as ComboBoxItemType, content: provider.content, - action: () => { - dispatch( - setNewestToolbarPreviewForInput({ - inputId, - contextItemId: provider.title, - }), - ); - - provider.action?.(); - }, + action: provider.action, })); if (query.length === 0 && commandItems.length === 0) {