Merge pull request #2482 from continuedev/tomasz/tooltips
Add tooltips to chat, fix @ and / commands when there's no preceding whitespace
This commit is contained in:
commit
c80531806f
8 changed files with 65 additions and 76 deletions
|
|
@ -1,9 +1,8 @@
|
|||
import React from "react";
|
||||
import ReactDOM from "react-dom";
|
||||
import { type PlacesType } from "react-tooltip";
|
||||
import { HeaderButton } from ".";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { ToolTip } from "./gui/Tooltip";
|
||||
import { ToolTip } from "./gui/Tooltip";
|
||||
|
||||
interface HeaderButtonWithTextProps {
|
||||
text: string | undefined;
|
||||
|
|
@ -26,8 +25,6 @@ const ButtonWithTooltip = React.forwardRef<
|
|||
HeaderButtonWithTextProps
|
||||
>((props: HeaderButtonWithTextProps, ref) => {
|
||||
const id = uuidv4();
|
||||
|
||||
const tooltipPortalDiv = document.getElementById("tooltip-portal-div");
|
||||
const tooltipId = `header_button_${id}`;
|
||||
|
||||
return (
|
||||
|
|
@ -47,14 +44,10 @@ const ButtonWithTooltip = React.forwardRef<
|
|||
>
|
||||
{props.children}
|
||||
</HeaderButton>
|
||||
{props.text &&
|
||||
tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<ToolTip id={tooltipId} place={props.tooltipPlacement ?? "bottom"}>
|
||||
{props.text}
|
||||
</ToolTip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
|
||||
<ToolTip id={tooltipId} place={props.tooltipPlacement ?? "bottom"}>
|
||||
{props.text}
|
||||
</ToolTip>
|
||||
</>
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,25 +1,19 @@
|
|||
import { InformationCircleIcon } from "@heroicons/react/24/outline";
|
||||
import ReactDOM from "react-dom";
|
||||
import { ToolTip } from "./gui/Tooltip";
|
||||
|
||||
const InfoHover = ({ msg }: { msg: string }) => {
|
||||
const id = `info-hover-${encodeURIComponent(msg)}`;
|
||||
|
||||
const tooltipPortalDiv = document.getElementById("tooltip-portal-div");
|
||||
|
||||
return (
|
||||
<>
|
||||
<InformationCircleIcon
|
||||
data-tooltip-id={id}
|
||||
className="h-5 w-5 text-gray-500 cursor-help"
|
||||
/>
|
||||
{tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<ToolTip id={id} place="bottom">
|
||||
{msg}
|
||||
</ToolTip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
|
||||
<ToolTip id={id} place="bottom">
|
||||
{msg}
|
||||
</ToolTip>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { CommandLineIcon } from "@heroicons/react/24/outline";
|
||||
import { useContext } from "react";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import ReactDOM from "react-dom";
|
||||
import { StyledActionButton } from "../..";
|
||||
import OllamaCompletedStep from "./OllamaCompletedStep";
|
||||
import { ToolTip } from "../../gui/Tooltip";
|
||||
|
|
@ -20,7 +19,6 @@ function OllamaModelDownload({
|
|||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const command = `ollama pull ${modelName}`;
|
||||
const id = `info-hover-${encodeURIComponent(command)}`;
|
||||
const tooltipPortalDiv = document.getElementById("tooltip-portal-div");
|
||||
|
||||
function onClick() {
|
||||
ideMessenger.ide.runCommand(command);
|
||||
|
|
@ -38,13 +36,10 @@ function OllamaModelDownload({
|
|||
<p className="font-mono truncate">{command}</p>
|
||||
<CommandLineIcon width={24} height={24} />
|
||||
</StyledActionButton>
|
||||
{tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<ToolTip id={id} place="top">
|
||||
Copy into terminal
|
||||
</ToolTip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
|
||||
<ToolTip id={id} place="top">
|
||||
Copy into terminal
|
||||
</ToolTip>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Tooltip } from "react-tooltip";
|
||||
import { vscInputBackground, vscBadgeBackground, vscForeground } from "..";
|
||||
import { getFontSize } from "../../util";
|
||||
import ReactDOM from "react-dom";
|
||||
|
||||
const TooltipStyles = {
|
||||
fontSize: `${getFontSize() - 2}px`,
|
||||
|
|
@ -20,5 +21,13 @@ export function ToolTip(props: any) {
|
|||
...props.style,
|
||||
};
|
||||
|
||||
return <Tooltip {...props} style={combinedStyles} />;
|
||||
const tooltipPortalDiv = document.getElementById("tooltip-portal-div");
|
||||
|
||||
return (
|
||||
tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<Tooltip {...props} style={combinedStyles} />,
|
||||
tooltipPortalDiv,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import { ExclamationCircleIcon } from "@heroicons/react/24/outline";
|
||||
import ReactDOM from "react-dom";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import AddModelForm from "../../forms/AddModelForm";
|
||||
|
|
@ -20,8 +19,6 @@ function FreeTrialProgressBar({ completed, total }: FreeTrialProgressBarProps) {
|
|||
const navigate = useNavigate();
|
||||
const fillPercentage = Math.min(100, Math.max(0, (completed / total) * 100));
|
||||
|
||||
const tooltipPortalDiv = document.getElementById("tooltip-portal-div");
|
||||
|
||||
function onClick() {
|
||||
dispatch(setShowDialog(true));
|
||||
dispatch(
|
||||
|
|
@ -46,13 +43,10 @@ function FreeTrialProgressBar({ completed, total }: FreeTrialProgressBarProps) {
|
|||
<ExclamationCircleIcon width="18px" height="18px" color="red" />
|
||||
Trial limit reached
|
||||
</div>
|
||||
{tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<ToolTip id="usage_progress_bar" place="top">
|
||||
Configure a model above in order to continue
|
||||
</ToolTip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
|
||||
<ToolTip id="usage_progress_bar" place="top">
|
||||
Configure a model above in order to continue
|
||||
</ToolTip>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
@ -85,14 +79,9 @@ function FreeTrialProgressBar({ completed, total }: FreeTrialProgressBarProps) {
|
|||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<ToolTip id="usage_progress_bar" place="top">
|
||||
{`Click to use your own API key or local LLM (required after ${FREE_TRIAL_LIMIT_REQUESTS} inputs)`}
|
||||
</ToolTip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
<ToolTip id="usage_progress_bar" place="top">
|
||||
{`Click to use your own API key or local LLM (required after ${FREE_TRIAL_LIMIT_REQUESTS} inputs)`}
|
||||
</ToolTip>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
isMetaEquivalentKeyPressed,
|
||||
} from "../../util";
|
||||
import ModelSelect from "../modelSelection/ModelSelect";
|
||||
import { ToolTip } from "../gui/Tooltip";
|
||||
|
||||
const StyledDiv = styled.div<{ isHidden: boolean }>`
|
||||
padding: 4px 0;
|
||||
|
|
@ -121,7 +122,14 @@ function InputToolbar(props: InputToolbarProps) {
|
|||
)}
|
||||
|
||||
<HoverItem onClick={props.onAddContextItem}>
|
||||
<AtSymbolIcon className="h-4 w-4" />
|
||||
<AtSymbolIcon
|
||||
data-tooltip-id="add-context-item-tooltip"
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
|
||||
<ToolTip id="add-context-item-tooltip" place="top-start">
|
||||
Add context (files, docs, urls, etc.)
|
||||
</ToolTip>
|
||||
</HoverItem>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -143,11 +151,12 @@ function InputToolbar(props: InputToolbarProps) {
|
|||
})
|
||||
}
|
||||
>
|
||||
<span className="hidden md:inline">
|
||||
{getMetaKeyLabel()}⏎ Use @codebase
|
||||
<span data-tooltip-id="add-codebase-context-tooltip">
|
||||
@codebase
|
||||
</span>
|
||||
|
||||
<span className="md:hidden">@codebase</span>
|
||||
<ToolTip id="add-codebase-context-tooltip" place="top-end">
|
||||
Submit with the codebase as context ({getMetaKeyLabel()}⏎)
|
||||
</ToolTip>
|
||||
</HoverItem>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import { modelSupportsImages } from "core/llm/autodetect";
|
|||
import { getBasename, getRelativePath } from "core/util";
|
||||
import { debounce } from "lodash";
|
||||
import { usePostHog } from "posthog-js/react";
|
||||
import { useContext, useEffect, useRef, useState } from "react";
|
||||
import { useCallback, useContext, useEffect, useRef, useState } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
import { v4 } from "uuid";
|
||||
|
|
@ -817,6 +817,20 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
|
||||
const [activeKey, setActiveKey] = useState<string | null>(null);
|
||||
|
||||
const insertCharacterWithWhitespace = useCallback(
|
||||
(char: string) => {
|
||||
const text = editor.getText();
|
||||
if (!text.endsWith(char)) {
|
||||
if (text.length > 0 && !text.endsWith(" ")) {
|
||||
editor.commands.insertContent(` ${char}`);
|
||||
} else {
|
||||
editor.commands.insertContent(char);
|
||||
}
|
||||
}
|
||||
},
|
||||
[editor],
|
||||
);
|
||||
|
||||
return (
|
||||
<InputBoxDiv
|
||||
onKeyDown={(e) => {
|
||||
|
|
@ -877,16 +891,8 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
<InputToolbar
|
||||
activeKey={activeKey}
|
||||
hidden={shouldHideToolbar && !props.isMainInput}
|
||||
onAddContextItem={() => {
|
||||
if (!editor.getText().endsWith("@")) {
|
||||
editor.commands.insertContent("@");
|
||||
}
|
||||
}}
|
||||
onAddSlashCommand={() => {
|
||||
if (!editor.getText().endsWith("/")) {
|
||||
editor.commands.insertContent("/");
|
||||
}
|
||||
}}
|
||||
onAddContextItem={() => insertCharacterWithWhitespace("@")}
|
||||
onAddSlashCommand={() => insertCharacterWithWhitespace("/")}
|
||||
onEnter={onEnterRef.current}
|
||||
onImageFileSelected={(file) => {
|
||||
handleImageFile(file).then(([img, dataUrl]) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import ReactDOM from "react-dom";
|
||||
import styled from "styled-components";
|
||||
import {
|
||||
defaultBorderRadius,
|
||||
|
|
@ -42,20 +41,15 @@ const keyToName: { [key: string]: string } = {
|
|||
};
|
||||
|
||||
function KeyDiv({ text }: { text: string }) {
|
||||
const tooltipPortalDiv = document.getElementById("tooltip-portal-div");
|
||||
|
||||
return (
|
||||
<>
|
||||
<StyledKeyDiv data-tooltip-id={`header_button_${text}`}>
|
||||
{text}
|
||||
</StyledKeyDiv>
|
||||
{tooltipPortalDiv &&
|
||||
ReactDOM.createPortal(
|
||||
<ToolTip id={`header_button_${text}`} place="bottom">
|
||||
{keyToName[text]}
|
||||
</ToolTip>,
|
||||
tooltipPortalDiv,
|
||||
)}
|
||||
|
||||
<ToolTip id={`header_button_${text}`} place="bottom">
|
||||
{keyToName[text]}
|
||||
</ToolTip>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue