Skip to content

feat: add insert at cursor functionality with tooltip #4936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ChevronDownIcon } from "@heroicons/react/24/outline";
import {
ArrowLeftEndOnRectangleIcon,
ChevronDownIcon,
} from "@heroicons/react/24/outline";
import { inferResolvedUriFromRelativePath } from "core/util/ideUtils";
import { useContext, useState } from "react";
import styled from "styled-components";
Expand All @@ -10,15 +13,16 @@ import {
import { IdeMessengerContext } from "../../../context/IdeMessenger";
import { useWebviewListener } from "../../../hooks/useWebviewListener";
import { useAppSelector } from "../../../redux/hooks";
import { selectDefaultModel } from "../../../redux/slices/configSlice";
import {
selectApplyStateByStreamId,
selectIsInEditMode,
} from "../../../redux/slices/sessionSlice";
import { getFontSize } from "../../../util";
import { isTerminalCodeBlock } from "../utils";
import { childrenToText, isTerminalCodeBlock } from "../utils";
import ApplyActions from "./ApplyActions";
import CopyButton from "./CopyButton";
import { FileInfo } from "./FileInfo";
import FileInfo from "./FileInfo";
import GeneratingCodeLoader from "./GeneratingCodeLoader";
import InsertButton from "./InsertButton";
import RunInTerminalButton from "./RunInTerminalButton";
Expand Down Expand Up @@ -90,6 +94,12 @@ export default function StepContainerPreToolbar({
selectApplyStateByStreamId(state, codeBlockStreamId),
);

const uiConfig = useAppSelector(selectUIConfig);
const isBottomToolbarPosition =
uiConfig?.codeBlockToolbarPosition == "bottom";

const toolTipPlacement = isBottomToolbarPosition ? "top" : "bottom";

Comment on lines +97 to +101
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is all of this logic necessary given that the toolbar position is either top or bottom?
https://github.com/aadarshkt/continue/blob/fix-insert-at-cursor/core/index.d.ts#L1099

How about something like the following instead?

              <HeaderButtonWithToolTip
                text="Insert at cursor"
                style={{ backgroundColor: vscEditorBackground }}
                onClick={() =>
                  ideMessenger.post("insertAtCursor", {
                    text: codeBlockContent,
                  })
                }
                tooltipPlacement={uiConfig?.codeBlockToolbarPosition ?? "top"}
              >

const isNextCodeBlock = nextCodeBlockIndex === codeBlockIndex;
const hasFileExtension =
relativeFilepath && /\.[0-9a-z]+$/i.test(relativeFilepath);
Expand Down Expand Up @@ -217,22 +227,22 @@ export default function StepContainerPreToolbar({
showLineCount={!isExpanded}
codeBlockContent={codeBlockContent}
/>
) : (
)}

{!isGeneratingCodeBlock && (
<>
<InsertButton onInsert={onClickInsertAtCursor} />
<CopyButton text={codeBlockContent} />

{isTerminalCodeBlock(language, codeBlockContent) ? (
<RunInTerminalButton command={codeBlockContent} />
) : (
<ApplyActions
disableManualApply={disableManualApply}
applyState={applyState}
onClickApply={onClickApply}
onClickAccept={() => handleDiffAction("accept")}
onClickReject={() => handleDiffAction("reject")}
/>
)}
<CopyButton text={props.codeBlockContent} />
{props.hideApply ||
(isTerminalCodeBlock(props.language, props.codeBlockContent) ? (
<RunInTerminalButton command={props.codeBlockContent} />
) : (
<ApplyActions
applyState={applyState}
onClickApply={onClickApply}
onClickAccept={onClickAcceptApply}
onClickReject={onClickRejectApply}
/>
))}
</>
)}
</div>
Expand Down
Loading