feat: separate toolbar action buttons
This commit is contained in:
parent
ad6c0d0bb8
commit
aba6e4e61c
22 changed files with 327 additions and 129 deletions
|
|
@ -11,7 +11,7 @@ import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
|||
import { RootState } from "../redux/store";
|
||||
import { FREE_TRIAL_LIMIT_REQUESTS } from "../util/freeTrial";
|
||||
import { ROUTES } from "../util/navigation";
|
||||
import ButtonWithTooltip from "./ButtonWithTooltip";
|
||||
import HeaderButtonWithToolTip from "./gui/HeaderButtonWithToolTip";
|
||||
import FreeTrialProgressBar from "./loaders/FreeTrialProgressBar";
|
||||
import ProfileSwitcher from "./ProfileSwitcher";
|
||||
|
||||
|
|
@ -60,30 +60,30 @@ function Footer() {
|
|||
|
||||
<div className="flex gap-1">
|
||||
{configError && (
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
tooltipPlacement="top-end"
|
||||
text="Config error"
|
||||
onClick={onClickError}
|
||||
>
|
||||
<ExclamationTriangleIcon className="h-4 w-4" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
)}
|
||||
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
tooltipPlacement="top-end"
|
||||
text="More"
|
||||
onClick={onClickMore}
|
||||
>
|
||||
<EllipsisHorizontalCircleIcon className="h-4 w-4" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
tooltipPlacement="top-end"
|
||||
onClick={onClickSettings}
|
||||
text="Configure Continue"
|
||||
>
|
||||
<Cog6ToothIcon className="h-4 w-4" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { useDispatch } from "react-redux";
|
|||
import { useNavigate } from "react-router-dom";
|
||||
import { Input } from "..";
|
||||
import useHistory from "../../hooks/useHistory";
|
||||
import ButtonWithTooltip from "../ButtonWithTooltip";
|
||||
import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
|
||||
|
||||
function lastPartOfPath(path: string): string {
|
||||
const sep = path.includes("/") ? "/" : "\\";
|
||||
|
|
@ -101,7 +101,7 @@ export function HistoryTableRow({
|
|||
|
||||
{hovered && !editing && (
|
||||
<div className="bg-vsc-background absolute right-2 top-1/2 ml-auto flex -translate-y-1/2 transform items-center gap-x-2 rounded-full py-1.5 pl-4 pr-4 shadow-md">
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
text="Edit"
|
||||
onClick={async (e) => {
|
||||
e.stopPropagation();
|
||||
|
|
@ -109,8 +109,8 @@ export function HistoryTableRow({
|
|||
}}
|
||||
>
|
||||
<PencilSquareIcon width="1.3em" height="1.3em" />
|
||||
</ButtonWithTooltip>
|
||||
<ButtonWithTooltip
|
||||
</HeaderButtonWithToolTip>
|
||||
<HeaderButtonWithToolTip
|
||||
text="Delete"
|
||||
onClick={async () => {
|
||||
await deleteSession(session.sessionId);
|
||||
|
|
@ -118,7 +118,7 @@ export function HistoryTableRow({
|
|||
}}
|
||||
>
|
||||
<TrashIcon width="1.3em" height="1.3em" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,20 +1,20 @@
|
|||
import ContinueLogo from "../../ContinueLogo";
|
||||
import ContinueLogo from "../../gui/ContinueLogo";
|
||||
import QuickStartSubmitButton from "../components/QuickStartSubmitButton";
|
||||
|
||||
function OnboardingQuickstartTab() {
|
||||
return (
|
||||
<div className="flex justify-center items-center w-full h-full">
|
||||
<div className="flex flex-col items-center justify-center w-full max-w-full px-4 xs:px-0 text-center">
|
||||
<div className="hidden xs:flex">
|
||||
<div className="flex h-full w-full items-center justify-center">
|
||||
<div className="xs:px-0 flex w-full max-w-full flex-col items-center justify-center px-4 text-center">
|
||||
<div className="xs:flex hidden">
|
||||
<ContinueLogo height={75} />
|
||||
</div>
|
||||
|
||||
<p className="text-sm w-full xs:w-3/4">
|
||||
<p className="xs:w-3/4 w-full text-sm">
|
||||
Quickly get up and running using our API keys. After this trial, we'll
|
||||
help you set up your own models.
|
||||
</p>
|
||||
|
||||
<p className="text-sm w-full xs:w-3/4">
|
||||
<p className="xs:w-3/4 w-full text-sm">
|
||||
To prevent abuse, we'll ask you to sign in to GitHub.
|
||||
</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import { useWebviewListener } from "../hooks/useWebviewListener";
|
|||
import { setLastControlServerBetaEnabledStatus } from "../redux/slices/miscSlice";
|
||||
import { RootState } from "../redux/store";
|
||||
import { getFontSize } from "../util";
|
||||
import ButtonWithTooltip from "./ButtonWithTooltip";
|
||||
import HeaderButtonWithToolTip from "./gui/HeaderButtonWithToolTip";
|
||||
|
||||
const StyledListbox = styled(Listbox)`
|
||||
background-color: ${vscBackground};
|
||||
|
|
@ -247,7 +247,7 @@ function ProfileSwitcher() {
|
|||
|
||||
{controlServerBetaEnabled &&
|
||||
(session?.account ? (
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
tooltipPlacement="top-end"
|
||||
text={
|
||||
session.account.label === ""
|
||||
|
|
@ -257,15 +257,15 @@ function ProfileSwitcher() {
|
|||
onClick={logout}
|
||||
>
|
||||
<UserCircleIconSolid className="h-4 w-4" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
) : (
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
tooltipPlacement="top-end"
|
||||
text="Click to login to Continue"
|
||||
onClick={login}
|
||||
>
|
||||
<UserCircleIconOutline className="h-4 w-4" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { vscForeground } from ".";
|
||||
import { vscForeground } from "..";
|
||||
|
||||
interface ContinueLogoProps {
|
||||
height?: number;
|
||||
|
|
@ -2,7 +2,7 @@ import { CheckIcon, ClipboardIcon } from "@heroicons/react/24/outline";
|
|||
import { useContext, useState } from "react";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { isJetBrains } from "../../util";
|
||||
import ButtonWithTooltip from "../ButtonWithTooltip";
|
||||
import HeaderButtonWithToolTip from "./HeaderButtonWithToolTip";
|
||||
import useCopy from "../../hooks/useCopy";
|
||||
|
||||
interface CopyIconButtonProps {
|
||||
|
|
@ -22,7 +22,7 @@ export function CopyIconButton({
|
|||
|
||||
return (
|
||||
<>
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
tooltipPlacement="top"
|
||||
tabIndex={tabIndex}
|
||||
text={copied ? "Copied" : "Copy"}
|
||||
|
|
@ -33,7 +33,7 @@ export function CopyIconButton({
|
|||
) : (
|
||||
<ClipboardIcon className={clipboardIconClassName} />
|
||||
)}
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { MinusCircleIcon, XMarkIcon } from "@heroicons/react/24/outline";
|
|||
import { ContinueError } from "core";
|
||||
import styled from "styled-components";
|
||||
import { defaultBorderRadius, vscBackground } from "..";
|
||||
import ButtonWithTooltip from "../ButtonWithTooltip";
|
||||
import HeaderButtonWithToolTip from "./HeaderButtonWithToolTip";
|
||||
|
||||
const Div = styled.div`
|
||||
padding: 8px;
|
||||
|
|
@ -29,12 +29,15 @@ function ErrorStepContainer(props: ErrorStepContainerProps) {
|
|||
display: "flex",
|
||||
}}
|
||||
>
|
||||
<ButtonWithTooltip text="Collapse" onClick={() => props.onClose()}>
|
||||
<HeaderButtonWithToolTip
|
||||
text="Collapse"
|
||||
onClick={() => props.onClose()}
|
||||
>
|
||||
<MinusCircleIcon width="1.3em" height="1.3em" />
|
||||
</ButtonWithTooltip>
|
||||
<ButtonWithTooltip text="Delete" onClick={() => props.onDelete()}>
|
||||
</HeaderButtonWithToolTip>
|
||||
<HeaderButtonWithToolTip text="Delete" onClick={() => props.onDelete()}>
|
||||
<XMarkIcon width="1.3em" height="1.3em" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
</div>
|
||||
<Div>
|
||||
<pre style={{ whiteSpace: "pre-wrap", wordWrap: "break-word" }}>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import React from "react";
|
||||
import { type PlacesType } from "react-tooltip";
|
||||
import { HeaderButton } from ".";
|
||||
import { HeaderButton } from "..";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { ToolTip } from "./gui/Tooltip";
|
||||
import { ToolTip } from "./Tooltip";
|
||||
|
||||
interface HeaderButtonWithTextProps {
|
||||
interface HeaderButtonWithToolTipProps {
|
||||
text: string | undefined;
|
||||
onClick?: (e: any) => void;
|
||||
children: React.ReactNode;
|
||||
|
|
@ -20,10 +20,10 @@ interface HeaderButtonWithTextProps {
|
|||
tooltipPlacement?: PlacesType;
|
||||
}
|
||||
|
||||
const ButtonWithTooltip = React.forwardRef<
|
||||
const HeaderButtonWithToolTip = React.forwardRef<
|
||||
HTMLButtonElement,
|
||||
HeaderButtonWithTextProps
|
||||
>((props: HeaderButtonWithTextProps, ref) => {
|
||||
HeaderButtonWithToolTipProps
|
||||
>((props: HeaderButtonWithToolTipProps, ref) => {
|
||||
const id = uuidv4();
|
||||
const tooltipId = `header_button_${id}`;
|
||||
|
||||
|
|
@ -52,4 +52,4 @@ const ButtonWithTooltip = React.forwardRef<
|
|||
);
|
||||
});
|
||||
|
||||
export default ButtonWithTooltip;
|
||||
export default HeaderButtonWithToolTip;
|
||||
|
|
@ -14,7 +14,7 @@ import { IdeMessengerContext } from "../../context/IdeMessenger";
|
|||
import useUIConfig from "../../hooks/useUIConfig";
|
||||
import { RootState } from "../../redux/store";
|
||||
import { getFontSize } from "../../util";
|
||||
import ButtonWithTooltip from "../ButtonWithTooltip";
|
||||
import HeaderButtonWithToolTip from "./HeaderButtonWithToolTip";
|
||||
import StyledMarkdownPreview from "../markdown/StyledMarkdownPreview";
|
||||
import { CopyIconButton } from "./CopyIconButton";
|
||||
|
||||
|
|
@ -116,23 +116,23 @@ function StepContainer(props: StepContainerProps) {
|
|||
}}
|
||||
>
|
||||
{truncatedEarly && (
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
tabIndex={-1}
|
||||
text="Continue generation"
|
||||
onClick={props.onContinueGeneration}
|
||||
>
|
||||
<BarsArrowDownIcon className="h-3.5 w-3.5 text-gray-500" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
)}
|
||||
|
||||
{props.index !== 1 && (
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
text="Delete"
|
||||
tabIndex={-1}
|
||||
onClick={props.onDelete}
|
||||
>
|
||||
<TrashIcon className="h-3.5 w-3.5 text-gray-500" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
)}
|
||||
|
||||
<CopyIconButton
|
||||
|
|
@ -142,7 +142,7 @@ function StepContainer(props: StepContainerProps) {
|
|||
checkIconClassName="h-3.5 w-3.5 text-green-400"
|
||||
/>
|
||||
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
text="Helpful"
|
||||
tabIndex={-1}
|
||||
onClick={() => sendFeedback(true)}
|
||||
|
|
@ -150,9 +150,9 @@ function StepContainer(props: StepContainerProps) {
|
|||
<HandThumbUpIcon
|
||||
className={`mx-0.5 h-3.5 w-3.5 ${feedback === true ? "text-green-400" : "text-gray-500"}`}
|
||||
/>
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
text="Unhelpful"
|
||||
tabIndex={-1}
|
||||
onClick={() => sendFeedback(false)}
|
||||
|
|
@ -160,7 +160,7 @@ function StepContainer(props: StepContainerProps) {
|
|||
<HandThumbDownIcon
|
||||
className={`h-3.5 w-3.5 ${feedback === false ? "text-red-400" : "text-gray-500"}`}
|
||||
/>
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import {
|
|||
setDialogMessage,
|
||||
setShowDialog,
|
||||
} from "../../redux/slices/uiStateSlice";
|
||||
import ButtonWithTooltip from "../ButtonWithTooltip";
|
||||
import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
|
||||
import FileIcon from "../FileIcon";
|
||||
import SafeImg from "../SafeImg";
|
||||
import AddDocsDialog from "../dialogs/AddDocsDialog";
|
||||
|
|
@ -375,7 +375,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
onClick={() => selectItem(index)}
|
||||
onMouseEnter={() => setSelectedIndex(index)}
|
||||
>
|
||||
<span className="flex justify-between w-full items-center">
|
||||
<span className="flex w-full items-center justify-between">
|
||||
<div className="flex items-center justify-center">
|
||||
{showFileIconForItem(item) && (
|
||||
<FileIcon
|
||||
|
|
@ -400,7 +400,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
opacity: index !== selectedIndex ? 0 : 1,
|
||||
minWidth: "30px",
|
||||
}}
|
||||
className="whitespace-nowrap overflow-hidden overflow-ellipsis ml-2 flex items-center"
|
||||
className="ml-2 flex items-center overflow-hidden overflow-ellipsis whitespace-nowrap"
|
||||
>
|
||||
{item.description}
|
||||
{item.type === "contextProvider" &&
|
||||
|
|
@ -414,7 +414,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
{item.subActions?.map((subAction) => {
|
||||
const Icon = ICONS_FOR_DROPDOWN[subAction.icon];
|
||||
return (
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
onClick={(e) => {
|
||||
subAction.action(item);
|
||||
e.stopPropagation();
|
||||
|
|
@ -424,7 +424,7 @@ const MentionList = forwardRef((props: MentionListProps, ref) => {
|
|||
text={undefined}
|
||||
>
|
||||
<Icon width="1.2em" height="1.2em" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
);
|
||||
})}
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import styled from "styled-components";
|
|||
import { defaultBorderRadius, lightGray, vscEditorBackground } from "..";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { getFontSize } from "../../util";
|
||||
import ButtonWithTooltip from "../ButtonWithTooltip";
|
||||
import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
|
||||
import FileIcon from "../FileIcon";
|
||||
import StyledMarkdownPreview from "./StyledMarkdownPreview";
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ interface CodeSnippetPreviewProps {
|
|||
editing?: boolean;
|
||||
}
|
||||
|
||||
const StyledHeaderButtonWithText = styled(ButtonWithTooltip)<{
|
||||
const StyledHeaderButtonWithText = styled(HeaderButtonWithToolTip)<{
|
||||
color?: string;
|
||||
}>`
|
||||
${(props) => props.color && `background-color: ${props.color};`}
|
||||
|
|
@ -125,7 +125,7 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) {
|
|||
<PencilIcon width="1.1em" height="1.1em" />
|
||||
</StyledHeaderButtonWithText>
|
||||
)}
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
text="Delete"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
|
|
@ -133,7 +133,7 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) {
|
|||
}}
|
||||
>
|
||||
<XMarkIcon width="1.1em" height="1.1em" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
</div>
|
||||
</PreviewMarkdownHeader>
|
||||
<div
|
||||
|
|
@ -151,7 +151,7 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) {
|
|||
</div>
|
||||
|
||||
{(codeBlockRef.current?.scrollHeight ?? 0) > MAX_PREVIEW_HEIGHT && (
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
className="absolute bottom-1 right-2"
|
||||
text={collapsed ? "Expand" : "Collapse"}
|
||||
>
|
||||
|
|
@ -166,7 +166,7 @@ function CodeSnippetPreview(props: CodeSnippetPreviewProps) {
|
|||
onClick={() => setCollapsed(true)}
|
||||
/>
|
||||
)}
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
)}
|
||||
</PreviewMarkdownDiv>
|
||||
);
|
||||
|
|
|
|||
130
gui/src/components/markdown/StepContainerPreActionButtons.tsx
Normal file
130
gui/src/components/markdown/StepContainerPreActionButtons.tsx
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
import { useContext, useRef, useState } from "react";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
CommandLineIcon,
|
||||
PlayIcon,
|
||||
ArrowLeftEndOnRectangleIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { defaultBorderRadius, vscEditorBackground } from "..";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { isJetBrains } from "../../util";
|
||||
import { isTerminalCodeBlock } from "./utils";
|
||||
import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
|
||||
import { CopyIconButton } from "../gui/CopyIconButton";
|
||||
import useUIConfig from "../../hooks/useUIConfig";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { useApplyCodeBlock } from "./utils/useApplyCodeBlock";
|
||||
|
||||
const TopDiv = styled.div`
|
||||
outline: 0.5px solid rgba(153, 153, 152);
|
||||
outline-offset: -0.5px;
|
||||
border-radius: ${defaultBorderRadius};
|
||||
margin-bottom: 8px;
|
||||
background-color: ${vscEditorBackground};
|
||||
`;
|
||||
|
||||
const HoverDiv = styled.div`
|
||||
position: sticky;
|
||||
top: 0;
|
||||
left: 100%;
|
||||
height: 0;
|
||||
width: 0;
|
||||
overflow: visible;
|
||||
z-index: 100;
|
||||
`;
|
||||
|
||||
const InnerHoverDiv = styled.div<{ isBottomToolbarPosition: boolean }>`
|
||||
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;
|
||||
codeBlockContent: string;
|
||||
filepath: string;
|
||||
children: any;
|
||||
}
|
||||
|
||||
export default function StepContainerPreActionButtons({
|
||||
language,
|
||||
codeBlockContent,
|
||||
filepath,
|
||||
children,
|
||||
}: StepContainerPreActionButtonsProps) {
|
||||
const [hovering, setHovering] = useState(false);
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const uiConfig = useUIConfig();
|
||||
const streamIdRef = useRef<string | null>(null);
|
||||
const onClickApply = useApplyCodeBlock({
|
||||
filepath,
|
||||
codeBlockContent,
|
||||
streamId: streamIdRef.current,
|
||||
});
|
||||
|
||||
const isBottomToolbarPosition =
|
||||
uiConfig?.codeBlockToolbarPosition == "bottom";
|
||||
const isTerminal = isTerminalCodeBlock(language, codeBlockContent);
|
||||
|
||||
if (streamIdRef.current === null) {
|
||||
streamIdRef.current = uuidv4();
|
||||
}
|
||||
|
||||
if (!hovering) {
|
||||
return (
|
||||
<TopDiv
|
||||
tabIndex={-1}
|
||||
onMouseEnter={() => setHovering(true)}
|
||||
onMouseLeave={() => setHovering(false)}
|
||||
>
|
||||
{children}
|
||||
</TopDiv>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<TopDiv
|
||||
tabIndex={-1}
|
||||
onMouseEnter={() => setHovering(true)}
|
||||
onMouseLeave={() => setHovering(false)}
|
||||
>
|
||||
<HoverDiv>
|
||||
<InnerHoverDiv isBottomToolbarPosition={isBottomToolbarPosition}>
|
||||
{!isJetBrains() && isTerminal && (
|
||||
<HeaderButtonWithToolTip
|
||||
text="Run in terminal"
|
||||
style={{ backgroundColor: vscEditorBackground }}
|
||||
onClick={onClickApply}
|
||||
>
|
||||
<CommandLineIcon className="h-4 w-4 text-gray-400" />
|
||||
</HeaderButtonWithToolTip>
|
||||
)}
|
||||
<HeaderButtonWithToolTip
|
||||
text="Apply"
|
||||
style={{ backgroundColor: vscEditorBackground }}
|
||||
onClick={onClickApply}
|
||||
>
|
||||
<PlayIcon className="h-4 w-4 text-gray-400" />
|
||||
</HeaderButtonWithToolTip>
|
||||
<HeaderButtonWithToolTip
|
||||
text="Insert at cursor"
|
||||
style={{ backgroundColor: vscEditorBackground }}
|
||||
onClick={() =>
|
||||
ideMessenger.post("insertAtCursor", { text: codeBlockContent })
|
||||
}
|
||||
>
|
||||
<ArrowLeftEndOnRectangleIcon className="h-4 w-4 text-gray-400" />
|
||||
</HeaderButtonWithToolTip>
|
||||
<CopyIconButton text={codeBlockContent} />
|
||||
</InnerHoverDiv>
|
||||
</HoverDiv>
|
||||
{children}
|
||||
</TopDiv>
|
||||
);
|
||||
}
|
||||
|
|
@ -52,8 +52,6 @@ export default function ApplyActions(props: ApplyActionsProps) {
|
|||
</div>
|
||||
);
|
||||
case "closed":
|
||||
// We show a codeblock as being "applied" whenever all individual diffs
|
||||
// have been accepted/rejected, or when a user has explicitly accepted the entire block.
|
||||
if (!hasRejected && props.applyState.numDiffs === 0) {
|
||||
return (
|
||||
<span className="flex items-center rounded bg-zinc-700 pl-2 pr-1 text-slate-400">
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import { RootState } from "../../../redux/store";
|
|||
import { getFontSize, isJetBrains } from "../../../util";
|
||||
import ApplyStateControls from "./ApplyActions";
|
||||
import FileInfo from "./FileInfo";
|
||||
import { isTerminalCodeBlock } from "./utils";
|
||||
import { isTerminalCodeBlock } from "../utils";
|
||||
|
||||
interface CodeBlockWithToolBarProps {
|
||||
text: string;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,12 @@
|
|||
import { debounce } from "lodash";
|
||||
import { useContext, useEffect, useRef, useState } from "react";
|
||||
import { useWebviewListener } from "../../../hooks/useWebviewListener";
|
||||
import {
|
||||
incrementNextCodeBlockToApplyIndex,
|
||||
updateApplyState,
|
||||
} from "../../../redux/slices/uiStateSlice";
|
||||
import { updateApplyState } from "../../../redux/slices/uiStateSlice";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { RootState } from "../../../redux/store";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import {
|
||||
childrenToText,
|
||||
getTerminalCommand,
|
||||
isTerminalCodeBlock,
|
||||
} from "./utils";
|
||||
import { childrenToText } from "../utils";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { defaultModelSelector } from "../../../redux/selectors/modelSelectors";
|
||||
import { defaultBorderRadius, lightGray, vscEditorBackground } from "../..";
|
||||
import { getFontSize } from "../../../util";
|
||||
import FileInfo from "./FileInfo";
|
||||
|
|
@ -23,7 +15,7 @@ import Spinner from "./Spinner";
|
|||
import ApplyActions from "./ApplyActions";
|
||||
import { ChevronDownIcon } from "@heroicons/react/24/outline";
|
||||
import CopyButton from "./CopyButton";
|
||||
import { ApplyState } from "core/protocol/ideWebview";
|
||||
import { useApplyCodeBlock } from "../utils/useApplyCodeBlock";
|
||||
|
||||
const TopDiv = styled.div`
|
||||
outline: 1px solid rgba(153, 153, 152);
|
||||
|
|
@ -61,10 +53,14 @@ export default function StepContainerPreToolbar(
|
|||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const streamIdRef = useRef<string | null>(null);
|
||||
const wasGeneratingRef = useRef(props.isGeneratingCodeBlock);
|
||||
const defaultModel = useSelector(defaultModelSelector);
|
||||
const [isExpanded, setIsExpanded] = useState(false);
|
||||
const [codeBlockContent, setCodeBlockContent] = useState("");
|
||||
const isChatActive = useSelector((state: RootState) => state.state.active);
|
||||
const onClickApply = useApplyCodeBlock({
|
||||
streamId: streamIdRef.current,
|
||||
filepath: props.filepath,
|
||||
codeBlockContent: props.codeBlockContent,
|
||||
});
|
||||
const nextCodeBlockIndex = useSelector(
|
||||
(state: RootState) => state.uiState.nextCodeBlockToApplyIndex,
|
||||
);
|
||||
|
|
@ -75,10 +71,6 @@ export default function StepContainerPreToolbar(
|
|||
),
|
||||
);
|
||||
|
||||
// console.log(
|
||||
// `[StepContainerPreToolbar] streamId: ${applyState && applyState.streamId} numDiffs: ${applyState && applyState.numDiffs}`,
|
||||
// );
|
||||
|
||||
const isMultifileEdit = true; // TODO: Pull from Redux state
|
||||
const numLinesCodeBlock = props.codeBlockContent.split("\n").length;
|
||||
|
||||
|
|
@ -135,24 +127,6 @@ export default function StepContainerPreToolbar(
|
|||
wasGeneratingRef.current = isGeneratingCodeBlock;
|
||||
}, [isGeneratingCodeBlock]);
|
||||
|
||||
async function onClickApply() {
|
||||
dispatch(
|
||||
updateApplyState({
|
||||
streamId: streamIdRef.current,
|
||||
status: "streaming",
|
||||
}),
|
||||
);
|
||||
|
||||
await ideMessenger.request("applyToFile", {
|
||||
text: codeBlockContent,
|
||||
streamId: streamIdRef.current,
|
||||
curSelectedModelTitle: defaultModel.title,
|
||||
filepath: props.filepath,
|
||||
});
|
||||
|
||||
dispatch(incrementNextCodeBlockToApplyIndex({}));
|
||||
}
|
||||
|
||||
function onClickAcceptApply() {
|
||||
ideMessenger.post("acceptDiff", { filepath: props.filepath });
|
||||
dispatch(
|
||||
|
|
@ -177,7 +151,8 @@ export default function StepContainerPreToolbar(
|
|||
setIsExpanded(!isExpanded);
|
||||
}
|
||||
|
||||
// If we don't have a file extension, we don't render any toolbar
|
||||
// We want until there is an extension in the filepath to avoid rendering
|
||||
// an incomplete filepath
|
||||
if (!hasFileExtension) {
|
||||
return props.children;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import {
|
|||
vscEditorBackground,
|
||||
vscForeground,
|
||||
} from "..";
|
||||
import { getFontSize } from "../../util";
|
||||
import { getFontSize, isJetBrains } from "../../util";
|
||||
import "./katex.css";
|
||||
import "./markdown.css";
|
||||
import { useSelector } from "react-redux";
|
||||
|
|
@ -20,6 +20,7 @@ import { ctxItemToRifWithContents } from "core/commands/util";
|
|||
import FilenameLink from "./FilenameLink";
|
||||
import StepContainerPreToolbar from "./StepContainerPreToolbar";
|
||||
import { SyntaxHighlightedPre } from "./SyntaxHighlightedPre";
|
||||
import StepContainerPreActionButtons from "./StepContainerPreActionButtons";
|
||||
|
||||
const StyledMarkdown = styled.div<{
|
||||
fontSize?: number;
|
||||
|
|
@ -194,22 +195,47 @@ const StyledMarkdownPreview = memo(function StyledMarkdownPreview(
|
|||
codeBlockContent,
|
||||
} = preProps?.children?.[0]?.props;
|
||||
|
||||
if (!filepath || !props.isRenderingInStepContainer) {
|
||||
if (!props.isRenderingInStepContainer) {
|
||||
return <SyntaxHighlightedPre {...preProps} />;
|
||||
}
|
||||
|
||||
// We use a custom toolbar for codeblocks in the step container
|
||||
const language = getLanuageFromClassName(className);
|
||||
|
||||
return (
|
||||
<StepContainerPreToolbar
|
||||
<StepContainerPreActionButtons
|
||||
language={language}
|
||||
codeBlockContent={codeBlockContent}
|
||||
codeBlockIndex={preProps.codeBlockIndex}
|
||||
language={getLanuageFromClassName(className)}
|
||||
filepath={filepath}
|
||||
isGeneratingCodeBlock={isGeneratingCodeBlock}
|
||||
>
|
||||
<SyntaxHighlightedPre {...preProps} />
|
||||
</StepContainerPreToolbar>
|
||||
</StepContainerPreActionButtons>
|
||||
);
|
||||
|
||||
// // We don't support "lazy" applies in JB yet
|
||||
// if (!filepath || isJetBrains()) {
|
||||
// return (
|
||||
// <StepContainerPreActionButtons
|
||||
// language={language}
|
||||
// codeBlockContent={codeBlockContent}
|
||||
// filepath={filepath}
|
||||
// >
|
||||
// <SyntaxHighlightedPre {...preProps} />
|
||||
// </StepContainerPreActionButtons>
|
||||
// );
|
||||
// }
|
||||
|
||||
// // We use a custom toolbar for codeblocks in the step container
|
||||
// return (
|
||||
// <StepContainerPreToolbar
|
||||
// codeBlockContent={codeBlockContent}
|
||||
// codeBlockIndex={preProps.codeBlockIndex}
|
||||
// language={language}
|
||||
// filepath={filepath}
|
||||
// isGeneratingCodeBlock={isGeneratingCodeBlock}
|
||||
// >
|
||||
// <SyntaxHighlightedPre {...preProps} />
|
||||
// </StepContainerPreToolbar>
|
||||
// );
|
||||
},
|
||||
code: ({ node, ...codeProps }) => {
|
||||
const content = getCodeChildrenContent(codeProps.children);
|
||||
|
|
|
|||
44
gui/src/components/markdown/utils/useApplyCodeBlock.ts
Normal file
44
gui/src/components/markdown/utils/useApplyCodeBlock.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { useContext } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import {
|
||||
incrementNextCodeBlockToApplyIndex,
|
||||
updateApplyState,
|
||||
} from "../../../redux/slices/uiStateSlice";
|
||||
import { defaultModelSelector } from "../../../redux/selectors/modelSelectors";
|
||||
|
||||
export interface useApplyCodeBlock {
|
||||
streamId: string;
|
||||
filepath: string;
|
||||
codeBlockContent: string;
|
||||
}
|
||||
|
||||
export function useApplyCodeBlock({
|
||||
streamId,
|
||||
filepath,
|
||||
codeBlockContent,
|
||||
}: useApplyCodeBlock) {
|
||||
const dispatch = useDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const defaultModel = useSelector(defaultModelSelector);
|
||||
|
||||
const applyCodeBlock = async () => {
|
||||
dispatch(
|
||||
updateApplyState({
|
||||
streamId,
|
||||
status: "streaming",
|
||||
}),
|
||||
);
|
||||
|
||||
await ideMessenger.request("applyToFile", {
|
||||
text: codeBlockContent,
|
||||
streamId,
|
||||
curSelectedModelTitle: defaultModel.title,
|
||||
filepath,
|
||||
});
|
||||
|
||||
dispatch(incrementNextCodeBlockToApplyIndex({}));
|
||||
};
|
||||
|
||||
return applyCodeBlock;
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import {
|
|||
} from "..";
|
||||
import { PackageDimension } from "../../pages/AddNewModel/configs/models";
|
||||
import { providers } from "../../pages/AddNewModel/configs/providers";
|
||||
import ButtonWithTooltip from "../ButtonWithTooltip";
|
||||
import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip";
|
||||
import InfoHover from "../InfoHover";
|
||||
import { ModelProviderTag } from "./ModelProviderTag";
|
||||
import { ModelProviderTags } from "./utils";
|
||||
|
|
@ -43,11 +43,11 @@ const Div = styled.div<{ color: string; disabled: boolean; hovered: boolean }>`
|
|||
opacity: 0.5;
|
||||
`
|
||||
: props.hovered
|
||||
? `
|
||||
? `
|
||||
border: 1px solid ${props.color};
|
||||
background-color: ${props.color}22;
|
||||
cursor: pointer;`
|
||||
: ""}
|
||||
: ""}
|
||||
`;
|
||||
|
||||
const DimensionsDiv = styled.div`
|
||||
|
|
@ -148,9 +148,7 @@ function ModelCard(props: ModelCardProps) {
|
|||
<h3>{props.title}</h3>
|
||||
</div>
|
||||
|
||||
{props.tags?.map((tag, i) => (
|
||||
<ModelProviderTag key={i} tag={tag} />
|
||||
))}
|
||||
{props.tags?.map((tag, i) => <ModelProviderTag key={i} tag={tag} />)}
|
||||
|
||||
<p>{props.description}</p>
|
||||
|
||||
|
|
@ -164,9 +162,9 @@ function ModelCard(props: ModelCardProps) {
|
|||
href={props.refUrl}
|
||||
target="_blank"
|
||||
>
|
||||
<ButtonWithTooltip text="Read the docs">
|
||||
<HeaderButtonWithToolTip text="Read the docs">
|
||||
<BookOpenIcon width="1.6em" height="1.6em" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
|
|
@ -179,7 +177,7 @@ function ModelCard(props: ModelCardProps) {
|
|||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center">
|
||||
<InfoHover msg={dimension.description} />
|
||||
<p className="mx-2 text-sm my-0 py-0">{dimension.name}</p>
|
||||
<p className="mx-2 my-0 py-0 text-sm">{dimension.name}</p>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
{Object.keys(dimension.options).map((key) => {
|
||||
|
|
@ -204,7 +202,7 @@ function ModelCard(props: ModelCardProps) {
|
|||
);
|
||||
})}
|
||||
{props.providerOptions?.length && (
|
||||
<div className="flex items-center flex-wrap justify-end rtl">
|
||||
<div className="rtl flex flex-wrap items-center justify-end">
|
||||
<div className="flex items-center">
|
||||
<InfoHover
|
||||
msg={
|
||||
|
|
@ -212,16 +210,16 @@ function ModelCard(props: ModelCardProps) {
|
|||
}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center flex-wrap justify-end rtl">
|
||||
<div className="rtl flex flex-wrap items-center justify-end">
|
||||
{props.providerOptions?.map((option, i) => {
|
||||
const info = providers[option];
|
||||
if (!info) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<ButtonWithTooltip
|
||||
<HeaderButtonWithToolTip
|
||||
text={info.title}
|
||||
className="p-2 text-center mx-1 items-center"
|
||||
className="mx-1 items-center p-2 text-center"
|
||||
style={{
|
||||
backgroundColor:
|
||||
(i === 0 &&
|
||||
|
|
@ -240,7 +238,7 @@ function ModelCard(props: ModelCardProps) {
|
|||
height="24px"
|
||||
/>
|
||||
)}
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { DiffEditor } from "@monaco-editor/react";
|
|||
import React, { useContext, useEffect } from "react";
|
||||
import { v4 } from "uuid";
|
||||
import { vscInputBackground } from "../components";
|
||||
import ButtonWithTooltip from "../components/ButtonWithTooltip";
|
||||
import HeaderButtonWithToolTip from "../components/gui/HeaderButtonWithToolTip";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
|
||||
interface EditorFrameProps {
|
||||
|
|
@ -37,7 +37,7 @@ function EditorFrame(props: EditorFrameProps) {
|
|||
return (
|
||||
<div>
|
||||
<div
|
||||
className="my-2 px-2 py-1 flex justify-between items-center"
|
||||
className="my-2 flex items-center justify-between px-2 py-1"
|
||||
style={{
|
||||
backgroundColor: vscInputBackground,
|
||||
}}
|
||||
|
|
@ -53,12 +53,12 @@ function EditorFrame(props: EditorFrameProps) {
|
|||
{props.filename.split("/").pop()}
|
||||
</code>
|
||||
<div className="flex items-center">
|
||||
<ButtonWithTooltip text="Reject" onClick={() => {}}>
|
||||
<HeaderButtonWithToolTip text="Reject" onClick={() => {}}>
|
||||
<XMarkIcon width="1.3em" height="1.3em" color="red" />
|
||||
</ButtonWithTooltip>
|
||||
<ButtonWithTooltip text="Accept" onClick={() => {}}>
|
||||
</HeaderButtonWithToolTip>
|
||||
<HeaderButtonWithToolTip text="Accept" onClick={() => {}}>
|
||||
<CheckIcon width="1.3em" height="1.3em" color="lightgreen" />
|
||||
</ButtonWithTooltip>
|
||||
</HeaderButtonWithToolTip>
|
||||
</div>
|
||||
</div>
|
||||
{/* <Editor
|
||||
|
|
|
|||
|
|
@ -64,10 +64,7 @@ export const uiStateSlice = createSlice({
|
|||
|
||||
const curApplyState = state.applyStates[index];
|
||||
|
||||
// console.log(
|
||||
// `[REDUX] streamId: ${streamId} status: ${status} numDiffs: ${action.payload.numDiffs}`,
|
||||
// );
|
||||
|
||||
// TODO: Verify this is not what's breaking the reject button for edit
|
||||
// if (payload.status === "closed" && index !== -1) {
|
||||
// state.applyStates.splice(index, 1);
|
||||
// } else
|
||||
|
|
|
|||
|
|
@ -7,4 +7,31 @@ class Calculator {
|
|||
this.result += number;
|
||||
return this;
|
||||
}
|
||||
|
||||
subtract(number) {
|
||||
this.result -= number;
|
||||
return this;
|
||||
}
|
||||
|
||||
multiply(number) {
|
||||
this.result *= number;
|
||||
return this;
|
||||
}
|
||||
|
||||
divide(number) {
|
||||
if (number === 0) {
|
||||
throw new Error("Cannot divide by zero");
|
||||
}
|
||||
this.result /= number;
|
||||
return this;
|
||||
}
|
||||
|
||||
getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.result = 0;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue