diff --git a/gui/src/components/mainInput/CodeBlockComponent.tsx b/gui/src/components/mainInput/CodeBlockComponent.tsx index 0a0e7996b..61403a261 100644 --- a/gui/src/components/mainInput/CodeBlockComponent.tsx +++ b/gui/src/components/mainInput/CodeBlockComponent.tsx @@ -6,6 +6,7 @@ import CodeSnippetPreview from "../markdown/CodeSnippetPreview"; export const CodeBlockComponent = (props: any) => { const { node, deleteNode, selected, editor, updateAttributes } = props; const item: ContextItemWithId = node.attrs.item; + const inputId = node.attrs.inputId; // const contextItems = useSelector( // (store: RootState) => // store.session.messages[store.session.messages.length - 1].contextItems, @@ -23,6 +24,7 @@ export const CodeBlockComponent = (props: any) => { as={nodeViewWrapperTag} > diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 232dafae3..f78b58720 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -50,6 +50,7 @@ import { selectHasCodeToEdit, selectIsInEditMode, setMainEditorContentTrigger, + setNewestCodeblocksForInput, } from "../../redux/slices/sessionSlice"; import { exitEditMode } from "../../redux/thunks"; import { @@ -108,11 +109,6 @@ const InputBoxDiv = styled.div<{ border?: string }>` flex-direction: column; `; -const PaddingDiv = styled.div` - padding: 8px 12px; - padding-bottom: 4px; -`; - const HoverDiv = styled.div` position: absolute; width: 100%; @@ -180,6 +176,7 @@ interface TipTapEditorProps { border?: string; placeholder?: string; historyKey: string; + inputId: string; } export const TIPPY_DIV_ID = "tippy-js-div"; @@ -782,22 +779,6 @@ function TipTapEditor(props: TipTapEditorProps) { return; } - // const rif: RangeInFile & { contents: string } = - // data.rangeInFileWithContents; - // const basename = getBasename(rif.filepath); - // const relativePath = getRelativePath( - // rif.filepath, - // await ideMessenger.ide.getWorkspaceDirs(), - // const rangeStr = `(${rif.range.start.line + 1}-${ - // rif.range.end.line + 1 - // })`; - - // const itemName = `${basename} ${rangeStr}`; - // const item: ContextItemWithId = { - // content: rif.contents, - // name: itemName - // } - const contextItem = rifWithContentsToContextItem( data.rangeInFileWithContents, ); @@ -819,10 +800,16 @@ function TipTapEditor(props: TipTapEditorProps) { type: "codeBlock", attrs: { item: contextItem, + inputId: props.inputId, }, }) .run(); - + dispatch( + setNewestCodeblocksForInput({ + inputId: props.inputId, + contextItemId: contextItem.id.itemId, + }), + ); if (data.prompt) { editor.commands.focus("end"); editor.commands.insertContent(data.prompt); @@ -990,8 +977,9 @@ function TipTapEditor(props: TipTapEditorProps) { event.preventDefault(); }} > - +
{ @@ -1023,7 +1011,7 @@ function TipTapEditor(props: TipTapEditorProps) { }} disabled={isStreaming} /> - +
{showDragOverMsg && modelSupportsImages( diff --git a/gui/src/components/markdown/CodeSnippetPreview.tsx b/gui/src/components/markdown/CodeSnippetPreview.tsx index 62565e5ea..06717c5ee 100644 --- a/gui/src/components/markdown/CodeSnippetPreview.tsx +++ b/gui/src/components/markdown/CodeSnippetPreview.tsx @@ -1,11 +1,11 @@ import { ChevronDownIcon, - ChevronUpIcon, + EyeSlashIcon, XMarkIcon, } from "@heroicons/react/24/outline"; import { ContextItemWithId } from "core"; import { dedent, getMarkdownLanguageTagForFile } from "core/util"; -import React, { useContext, useMemo } from "react"; +import { useContext, useEffect, useMemo, useRef, useState } from "react"; import styled from "styled-components"; import { defaultBorderRadius, lightGray, vscEditorBackground } from ".."; import { IdeMessengerContext } from "../../context/IdeMessenger"; @@ -14,6 +14,8 @@ import FileIcon from "../FileIcon"; import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; import StyledMarkdownPreview from "./StyledMarkdownPreview"; import { ctxItemToRifWithContents } from "core/commands/util"; +import { EyeIcon } from "@heroicons/react/24/solid"; +import { useAppSelector } from "../../redux/hooks"; const PreviewMarkdownDiv = styled.div<{ borderColor?: string; @@ -31,32 +33,30 @@ const PreviewMarkdownDiv = styled.div<{ } `; -const PreviewMarkdownHeader = styled.div` - margin: 0; - padding: 2px 6px; - border-bottom: 0.5px solid ${lightGray}; - word-break: break-all; - font-size: ${getFontSize() - 3}px; - display: flex; - align-items: center; -`; - interface CodeSnippetPreviewProps { item: ContextItemWithId; onDelete?: () => void; borderColor?: string; - hideHeader?: boolean; + inputId: string; } -const MAX_PREVIEW_HEIGHT = 300; +const MAX_PREVIEW_HEIGHT = 100; const backticksRegex = /`{3,}/gm; function CodeSnippetPreview(props: CodeSnippetPreviewProps) { const ideMessenger = useContext(IdeMessengerContext); - const [collapsed, setCollapsed] = React.useState(true); - const [hovered, setHovered] = React.useState(false); + const [localHidden, setLocalHidden] = useState(); + const [isSizeLimited, setIsSizeLimited] = useState(true); + + const newestCodeblockForInputId = useAppSelector( + (store) => store.session.newestCodeblockForInput[props.inputId], + ); + + const hidden = useMemo(() => { + return localHidden ?? newestCodeblockForInputId !== props.item.id.itemId; + }, [localHidden, newestCodeblockForInputId, props.item]); const content = useMemo(() => { return dedent`${props.item.content}`; @@ -67,20 +67,45 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) { return backticks ? backticks.sort().at(-1) + "`" : "```"; }, [content]); - const codeBlockRef = React.useRef(null); + const codeBlockRef = useRef(null); + + const [codeblockDims, setCodeblockDims] = useState({ width: 0, height: 0 }); + useEffect(() => { + const resizeObserver = new ResizeObserver(() => { + setCodeblockDims({ + width: codeBlockRef.current?.scrollWidth ?? 0, + height: codeBlockRef.current?.scrollHeight ?? 0, + }); + }); + + if (codeBlockRef.current) { + resizeObserver.observe(codeBlockRef.current); + } + + return () => { + resizeObserver.disconnect(); + }; + }, [codeBlockRef]); return ( setHovered(true)} - onMouseLeave={() => setHovered(false)} borderColor={props.borderColor} className="find-widget-skip" > - {!props.hideHeader && ( - { +
{ + setLocalHidden(!hidden); + }} + > +
{ + e.stopPropagation(); if ( props.item.id.providerTitle === "file" && props.item.uri?.value @@ -103,29 +128,34 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) { } }} > -
- - {props.item.name} -
-
- { - e.stopPropagation(); - props.onDelete?.(); - }} - > - - -
- - )} + + {props.item.name} +
+
+ + {hidden ? ( + + ) : ( + + )} + + { + e.stopPropagation(); + props.onDelete?.(); + }} + > + + +
+
- {(codeBlockRef.current?.scrollHeight ?? 0) > MAX_PREVIEW_HEIGHT && ( + {codeblockDims.height > MAX_PREVIEW_HEIGHT && ( - {collapsed ? ( - setCollapsed(false)} - /> - ) : ( - setCollapsed(true)} - /> - )} + setIsSizeLimited((v) => !v)} + /> )}
diff --git a/gui/src/editorInset/EditorInset.tsx b/gui/src/editorInset/EditorInset.tsx index 43942ea0c..3e90926b1 100644 --- a/gui/src/editorInset/EditorInset.tsx +++ b/gui/src/editorInset/EditorInset.tsx @@ -36,6 +36,7 @@ function EditorInset() { console.log("Enter: ", e, modifiers); }} historyKey="chat" + inputId="editor-inset" /> ); diff --git a/gui/src/index.css b/gui/src/index.css index fb5a0fe90..d51fbf004 100644 --- a/gui/src/index.css +++ b/gui/src/index.css @@ -102,3 +102,32 @@ body { direction: rtl; width: 100%; } + +.scroll-container { + overflow-y: auto; /* Enable vertical scrolling only if needed */ + scrollbar-width: thin; /* Firefox */ + padding-right: 4px; +} + +.scroll-container::-webkit-scrollbar { + width: 8px; +} + +.scroll-container::-webkit-scrollbar-track { + background: #f1f1f1; + border-radius: 4px; +} + +.scroll-container::-webkit-scrollbar-thumb { + background-color: #888; + border-radius: 4px; + transition: background-color 0.3s ease; +} + +.scroll-container::-webkit-scrollbar-thumb:hover { + background-color: #555; +} + +.scroll-container:is(:hover, :focus)::-webkit-scrollbar { + display: block; /* Show scrollbar only on hover or focus */ +} diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 1bb5f5714..7184a3be7 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -407,6 +407,7 @@ export function Chat() { isMainInput={false} editorState={item.editorState} contextItems={item.contextItems} + inputId={item.message.id} /> ) : item.message.role === "tool" ? ( @@ -503,6 +504,7 @@ export function Chat() { onEnter={(editorState, modifiers, editor) => sendInput(editorState, modifiers, undefined, editor) } + inputId={"main-editor"} /> )} diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 2ece67b85..7f66c6ec2 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -57,6 +57,7 @@ type SessionState = { states: ApplyState[]; curIndex: number; }; + newestCodeblockForInput: Record; }; function isCodeToEditEqual(a: CodeToEdit, b: CodeToEdit) { @@ -108,6 +109,7 @@ const initialState: SessionState = { curIndex: 0, }, lastSessionId: undefined, + newestCodeblockForInput: {}, }; export const sessionSlice = createSlice({ @@ -643,6 +645,17 @@ export const sessionSlice = createSlice({ setMode: (state, action: PayloadAction) => { state.mode = action.payload; }, + setNewestCodeblocksForInput: ( + state, + { + payload, + }: PayloadAction<{ + inputId: string; + contextItemId: string; + }>, + ) => { + state.newestCodeblockForInput[payload.inputId] = payload.contextItemId; + }, }, selectors: { selectIsGatheringContext: (state) => { @@ -741,6 +754,7 @@ export const { addSessionMetadata, updateSessionMetadata, deleteSessionMetadata, + setNewestCodeblocksForInput, } = sessionSlice.actions; export const {