From c8b47ea7ad26338a2e9d3c52289030ea3c252964 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 22 Jan 2025 17:43:01 -0800 Subject: [PATCH] codeblock action button makeover --- gui/src/components/gui/CopyIconButton.tsx | 7 +- .../StepContainerPreActionButtons.tsx | 76 ++++++------------- 2 files changed, 27 insertions(+), 56 deletions(-) diff --git a/gui/src/components/gui/CopyIconButton.tsx b/gui/src/components/gui/CopyIconButton.tsx index 5600420269..c2fcfd3229 100644 --- a/gui/src/components/gui/CopyIconButton.tsx +++ b/gui/src/components/gui/CopyIconButton.tsx @@ -1,7 +1,4 @@ import { CheckIcon, ClipboardIcon } from "@heroicons/react/24/outline"; -import { useContext, useState } from "react"; -import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { isJetBrains } from "../../util"; import HeaderButtonWithToolTip from "./HeaderButtonWithToolTip"; import useCopy from "../../hooks/useCopy"; @@ -10,6 +7,7 @@ interface CopyIconButtonProps { tabIndex?: number; checkIconClassName?: string; clipboardIconClassName?: string; + tooltipPlacement?: "top" | "bottom"; } export function CopyIconButton({ @@ -17,13 +15,14 @@ export function CopyIconButton({ tabIndex, checkIconClassName = "h-4 w-4 text-green-400", clipboardIconClassName = "h-4 w-4 text-gray-400", + tooltipPlacement = "bottom", }: CopyIconButtonProps) { const { copyText, copied } = useCopy(text); return ( <> ` - position: absolute; - ${(props) => (props.isBottomToolbarPosition ? "bottom: 3px;" : "top: -11px;")} - right: 10px; - display: flex; - padding: 1px 2px; - gap: 4px; - border: 0.5px solid #8888; - border-radius: ${defaultBorderRadius}; - background-color: ${vscEditorBackground}; -`; - interface StepContainerPreActionButtonsProps { language: string | null; codeBlockContent: string; @@ -69,9 +38,12 @@ export default function StepContainerPreActionButtons({ const nextCodeBlockIndex = useAppSelector( (state) => state.session.codeBlockApplyStates.curIndex, ); - + const isStreaming = useAppSelector((state) => state.session.isStreaming); const isBottomToolbarPosition = uiConfig?.codeBlockToolbarPosition == "bottom"; + + const toolTipPlacement = isBottomToolbarPosition ? "top" : "bottom"; + const shouldRunTerminalCmd = !isJetBrains() && isTerminalCodeBlock(language, codeBlockContent); const isNextCodeBlock = nextCodeBlockIndex === codeBlockIndex; @@ -107,31 +79,27 @@ export default function StepContainerPreActionButtons({ !isNextCodeBlock, ); - if (!hovering) { - return ( - setHovering(true)} - onMouseLeave={() => setHovering(false)} - > - {children} - - ); - } - return ( - setHovering(true)} onMouseLeave={() => setHovering(false)} + className="bg-vsc-editor-background border-vsc-input-border relative rounded-md border-[1px] border-solid" > - - +
{children}
+ {hovering && !isStreaming && ( +
{shouldRunTerminalCmd && ( @@ -140,6 +108,7 @@ export default function StepContainerPreActionButtons({ text="Apply" style={{ backgroundColor: vscEditorBackground }} onClick={onClickApply} + tooltipPlacement={toolTipPlacement} > @@ -149,13 +118,16 @@ export default function StepContainerPreActionButtons({ onClick={() => ideMessenger.post("insertAtCursor", { text: codeBlockContent }) } + tooltipPlacement={toolTipPlacement} > - - - - {children} - + +
+ )} + ); }