From 4f371a0eb654067c626a41eb53718f565873975b Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 22 May 2025 14:45:27 -0700 Subject: [PATCH 01/11] feat: remove edit as a mode --- core/index.d.ts | 2 +- extensions/vscode/package-lock.json | 4 +- .../components/History/HistoryTableRow.tsx | 4 +- gui/src/components/History/index.tsx | 2 + gui/src/components/Layout.tsx | 22 +-- gui/src/components/ModeSelect/ModeIcon.tsx | 21 ++ .../ModeSelect.tsx | 118 +++--------- gui/src/components/ModeSelect/index.ts | 1 + .../components/mainInput/CodeToEditCard.tsx | 181 ------------------ .../components/mainInput/ContinueInputBox.tsx | 35 ++-- .../components/mainInput/EditModeDetails.tsx | 10 +- gui/src/components/mainInput/InputToolbar.tsx | 30 +-- .../components/mainInput/Lump/LumpToolbar.tsx | 139 -------------- .../BlockSettingsTopToolbar.tsx | 20 +- .../Lump/LumpToolbar/EditToolbar.tsx | 41 ++++ .../Lump/LumpToolbar/GeneratingIndicator.tsx | 10 + .../Lump/LumpToolbar/LumpToolbar.tsx | 62 ++++++ .../LumpToolbar/PendingToolCallToolbar.tsx | 59 ++++++ .../Lump/LumpToolbar/StreamingToolbar.tsx | 43 +++++ .../Lump/LumpToolbar/TtsActiveToolbar.tsx | 37 ++++ .../mainInput/Lump/LumpToolbar/index.ts | 1 + gui/src/components/mainInput/Lump/index.tsx | 2 +- .../TipTapEditor/MainEditorProvider.tsx | 13 +- .../mainInput/TipTapEditor/TipTapEditor.tsx | 15 +- .../TipTapEditor/utils/editorConfig.ts | 16 +- gui/src/components/mainInput/util/index.ts | 20 ++ .../mainInput/util/inputModifiers.ts | 6 - gui/src/components/mainInput/utils.ts | 18 -- .../components/modelSelection/ModelSelect.tsx | 24 +-- gui/src/hooks/ParallelListeners.tsx | 61 +++--- gui/src/hooks/useNavigationListener.tsx | 1 + gui/src/pages/gui/Chat.tsx | 46 +++-- gui/src/redux/slices/sessionSlice.ts | 6 + gui/src/redux/thunks/{editMode.ts => edit.ts} | 28 ++- gui/src/redux/thunks/index.ts | 18 +- 35 files changed, 510 insertions(+), 606 deletions(-) create mode 100644 gui/src/components/ModeSelect/ModeIcon.tsx rename gui/src/components/{modelSelection => ModeSelect}/ModeSelect.tsx (51%) create mode 100644 gui/src/components/ModeSelect/index.ts delete mode 100644 gui/src/components/mainInput/CodeToEditCard.tsx delete mode 100644 gui/src/components/mainInput/Lump/LumpToolbar.tsx rename gui/src/components/mainInput/Lump/{ => LumpToolbar}/BlockSettingsTopToolbar.tsx (89%) create mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/EditToolbar.tsx create mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx create mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx create mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx create mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx create mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/TtsActiveToolbar.tsx create mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/index.ts create mode 100644 gui/src/components/mainInput/util/index.ts delete mode 100644 gui/src/components/mainInput/util/inputModifiers.ts delete mode 100644 gui/src/components/mainInput/utils.ts rename gui/src/redux/thunks/{editMode.ts => edit.ts} (85%) diff --git a/core/index.d.ts b/core/index.d.ts index 8cf7b8cb8..c5df0aee4 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -423,7 +423,7 @@ export interface PromptLog { completion: string; } -export type MessageModes = "chat" | "edit" | "agent"; +export type MessageModes = "chat" | "agent"; export type ToolStatus = | "generating" diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 681895a55..313cf7175 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.37", + "version": "1.1.38", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.37", + "version": "1.1.38", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", diff --git a/gui/src/components/History/HistoryTableRow.tsx b/gui/src/components/History/HistoryTableRow.tsx index 91854a274..9b037a068 100644 --- a/gui/src/components/History/HistoryTableRow.tsx +++ b/gui/src/components/History/HistoryTableRow.tsx @@ -6,7 +6,7 @@ import { useNavigate } from "react-router-dom"; import { Input } from ".."; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { exitEditMode } from "../../redux/thunks/editMode"; +import { exitEdit } from "../../redux/thunks/edit"; import { deleteSession, getSession, @@ -69,7 +69,7 @@ export function HistoryTableRow({ data-testid={`history-row-${index}`} className="hover:bg-vsc-editor-background relative box-border flex cursor-pointer overflow-hidden rounded-lg p-3" onClick={async () => { - await dispatch(exitEditMode({})); + await dispatch(exitEdit({})); if (sessionMetadata.sessionId !== currentSessionId) { await dispatch( loadSession({ diff --git a/gui/src/components/History/index.tsx b/gui/src/components/History/index.tsx index e51dc45eb..8d96715cf 100644 --- a/gui/src/components/History/index.tsx +++ b/gui/src/components/History/index.tsx @@ -13,6 +13,7 @@ import Shortcut from "../gui/Shortcut"; import { XMarkIcon } from "@heroicons/react/24/solid"; import { useNavigate } from "react-router-dom"; import { IdeMessengerContext } from "../../context/IdeMessenger"; +import { useNavigationListener } from "../../hooks/useNavigationListener"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { newSession, @@ -37,6 +38,7 @@ const HEADER_CLASS = "flex user-select-none pt-2 pb-3 opacity-75 text-center font-bold items-center justify-center sticky h-6"; export function History() { + useNavigationListener(); const dispatch = useAppDispatch(); const navigate = useNavigate(); const searchInputRef = React.useRef(null); diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index a6368eab4..6a08a9f8c 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -9,7 +9,7 @@ import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; import { setCodeToEdit } from "../redux/slices/editModeState"; import { setShowDialog } from "../redux/slices/uiSlice"; -import { enterEditMode, exitEditMode } from "../redux/thunks/editMode"; +import { enterEdit, exitEdit } from "../redux/thunks/edit"; import { saveCurrentSession } from "../redux/thunks/session"; import { fontSize, isMetaEquivalentKeyPressed } from "../util"; import { incrementFreeTrialCount } from "../util/freeTrial"; @@ -48,14 +48,14 @@ const Layout = () => { const dialogMessage = useAppSelector((state) => state.ui.dialogMessage); const showDialog = useAppSelector((state) => state.ui.showDialog); - const mode = useAppSelector((state) => state.session.mode); + const isInEdit = useAppSelector((store) => store.session.isInEdit); useWebviewListener( "newSession", async () => { navigate(ROUTES.HOME); - if (mode === "edit") { - await dispatch(exitEditMode({})); + if (isInEdit) { + await dispatch(exitEdit({})); } else { await dispatch( saveCurrentSession({ @@ -65,7 +65,7 @@ const Layout = () => { ); } }, - [mode], + [isInEdit], ); useWebviewListener( @@ -81,9 +81,9 @@ const Layout = () => { "focusContinueInputWithNewSession", async () => { navigate(ROUTES.HOME); - if (mode === "edit") { + if (isInEdit) { await dispatch( - exitEditMode({ + exitEdit({ openNewSession: true, }), ); @@ -96,7 +96,7 @@ const Layout = () => { ); } }, - [location.pathname, mode], + [location.pathname, isInEdit], location.pathname === ROUTES.HOME, ); @@ -148,7 +148,7 @@ const Layout = () => { "focusEdit", async () => { await ideMessenger.request("edit/addCurrentSelection", undefined); - await dispatch(enterEditMode({})); + await dispatch(enterEdit({})); mainEditor?.commands.focus(); }, [ideMessenger, mainEditor], @@ -169,7 +169,7 @@ const Layout = () => { useWebviewListener( "exitEditMode", async () => { - await dispatch(exitEditMode({})); + await dispatch(exitEdit({})); }, [], ); @@ -181,7 +181,7 @@ const Layout = () => { if (selection) { // Copy to clipboard setTimeout(() => { - navigator.clipboard.writeText(selection); + void navigator.clipboard.writeText(selection); }, 100); } } diff --git a/gui/src/components/ModeSelect/ModeIcon.tsx b/gui/src/components/ModeSelect/ModeIcon.tsx new file mode 100644 index 000000000..0b95ff4bc --- /dev/null +++ b/gui/src/components/ModeSelect/ModeIcon.tsx @@ -0,0 +1,21 @@ +import { ChatBubbleLeftIcon, SparklesIcon } from "@heroicons/react/24/outline"; +import { MessageModes } from "core"; + +interface ModeIconProps { + mode: MessageModes; + className?: string; +} + +function ModeIcon({ + mode, + className = "xs:h-3 xs:w-3 h-3 w-3", +}: ModeIconProps) { + switch (mode) { + case "agent": + return ; + case "chat": + return ; + } +} + +export default ModeIcon; diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/ModeSelect/ModeSelect.tsx similarity index 51% rename from gui/src/components/modelSelection/ModeSelect.tsx rename to gui/src/components/ModeSelect/ModeSelect.tsx index 23caef356..b0fd1eee1 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/ModeSelect/ModeSelect.tsx @@ -1,21 +1,11 @@ -// A dropdown menu for selecting between Chat, Edit, and Agent modes with keyboard shortcuts -import { - ChatBubbleLeftIcon, - CheckIcon, - ChevronDownIcon, - PencilIcon, - SparklesIcon, -} from "@heroicons/react/24/outline"; +import { CheckIcon, ChevronDownIcon } from "@heroicons/react/24/outline"; import { MessageModes } from "core"; import { modelSupportsTools } from "core/llm/autodetect"; import { useCallback, useEffect, useMemo } from "react"; -import styled from "styled-components"; -import { lightGray } from ".."; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { setMode } from "../../redux/slices/sessionSlice"; -import { enterEditMode, exitEditMode } from "../../redux/thunks/editMode"; -import { getFontSize, getMetaKeyLabel, isJetBrains } from "../../util"; +import { getFontSize, getMetaKeyLabel } from "../../util"; import { useMainEditor } from "../mainInput/TipTapEditor"; import { Listbox, @@ -23,14 +13,9 @@ import { ListboxOption, ListboxOptions, } from "../ui/Listbox"; +import ModeIcon from "./ModeIcon"; -const ShortcutText = styled.span` - color: ${lightGray}; - font-size: ${getFontSize() - 3}px; - margin-right: auto; -`; - -function ModeSelect() { +export function ModeSelect() { const dispatch = useAppDispatch(); const mode = useAppSelector((store) => store.session.mode); const selectedModel = useAppSelector(selectSelectedChatModel); @@ -38,24 +23,10 @@ function ModeSelect() { return selectedModel && modelSupportsTools(selectedModel); }, [selectedModel]); const { mainEditor } = useMainEditor(); - const jetbrains = useMemo(() => { - return isJetBrains(); - }, []); const metaKeyLabel = useMemo(() => { return getMetaKeyLabel(); }, []); - const getModeIcon = (mode: MessageModes) => { - switch (mode) { - case "agent": - return ; - case "chat": - return ; - case "edit": - return ; - } - }; - // Switch to chat mode if agent mode is selected but not supported useEffect(() => { if (!selectedModel) { @@ -66,55 +37,22 @@ function ModeSelect() { } }, [mode, agentModeSupported, dispatch, selectedModel]); - const cycleMode = useCallback(async () => { - const modes: MessageModes[] = jetbrains - ? ["chat", "agent"] - : ["chat", "agent", "edit"]; - const currentIndex = modes.indexOf(mode); - const nextMode = modes[(currentIndex + 1) % modes.length]; - - if (mode === "edit") { - await dispatch( - exitEditMode({ - goToMode: nextMode, - }), - ); + const cycleMode = useCallback(() => { + if (mode === "chat" && agentModeSupported) { + dispatch(setMode("agent")); } else { - if (nextMode === "edit") { - await dispatch( - enterEditMode({ - returnToMode: mode, - }), - ); - } else { - dispatch(setMode(nextMode)); - } + dispatch(setMode("chat")); } mainEditor?.commands.focus(); - }, [jetbrains, mode, mainEditor]); + }, [mode, agentModeSupported, mainEditor]); const selectMode = useCallback( - async (newMode: MessageModes) => { + (newMode: MessageModes) => { if (newMode === mode) { return; } - if (newMode === "edit") { - await dispatch( - enterEditMode({ - returnToMode: mode, - }), - ); - } else { - if (mode === "edit") { - await dispatch( - exitEditMode({ - goToMode: newMode, - }), - ); - } else { - dispatch(setMode(newMode)); - } - } + + dispatch(setMode(newMode)); mainEditor?.commands.focus(); }, @@ -138,13 +76,9 @@ function ModeSelect() {
- {getModeIcon(mode)} + {mode.charAt(0).toUpperCase() + mode.slice(1)} @@ -154,21 +88,15 @@ function ModeSelect() { /> - {!jetbrains && ( - -
- - Edit - {getMetaKeyLabel()}I -
- {mode === "edit" && } -
- )}
- + Chat - {getMetaKeyLabel()}L + + {getMetaKeyLabel()}L +
{mode === "chat" && }
@@ -179,7 +107,7 @@ function ModeSelect() { className={"gap-1"} >
- + Agent
{agentModeSupported ? ( @@ -189,7 +117,7 @@ function ModeSelect() { )} -
+
{`${metaKeyLabel} . for next mode`}
@@ -197,5 +125,3 @@ function ModeSelect() { ); } - -export default ModeSelect; diff --git a/gui/src/components/ModeSelect/index.ts b/gui/src/components/ModeSelect/index.ts new file mode 100644 index 000000000..04cc20156 --- /dev/null +++ b/gui/src/components/ModeSelect/index.ts @@ -0,0 +1 @@ +export * from "./ModeSelect"; diff --git a/gui/src/components/mainInput/CodeToEditCard.tsx b/gui/src/components/mainInput/CodeToEditCard.tsx deleted file mode 100644 index 1c22f5ddf..000000000 --- a/gui/src/components/mainInput/CodeToEditCard.tsx +++ /dev/null @@ -1,181 +0,0 @@ -import { ChevronRightIcon, XMarkIcon } from "@heroicons/react/24/outline"; -import { SetCodeToEditPayload } from "core"; -import { getMarkdownLanguageTagForFile } from "core/util"; -import { getUriPathBasename } from "core/util/uri"; -import { useContext, useMemo, useState } from "react"; -import { useDispatch } from "react-redux"; -import styled from "styled-components"; -import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { useAppSelector } from "../../redux/hooks"; -import { clearCodeToEdit } from "../../redux/slices/editModeState"; -import { getMetaKeyLabel } from "../../util"; -import FileIcon from "../FileIcon"; -import StyledMarkdownPreview from "../StyledMarkdownPreview"; -import { useFontSize } from "../ui/font"; - -const NoPaddingWrapper = styled.div` - > * { - margin: 0 !important; - padding: 0 !important; - } - - pre { - margin: 0 !important; - padding: 0px 0px 0px 10px !important; - } -`; - -interface CodeToEditItemProps { - code: SetCodeToEditPayload; -} - -function CodeToEditItem({ code }: CodeToEditItemProps) { - const dispatch = useDispatch(); - const ideMessenger = useContext(IdeMessengerContext); - const [showCodeSnippet, setShowCodeSnippet] = useState(false); - - function onDelete() { - dispatch(clearCodeToEdit()); - ideMessenger.post("edit/clearDecorations", undefined); - } - - const fileName = getUriPathBasename(code.filepath); - - let isInsertion = false; - let title = fileName; - - if ("range" in code) { - const start = code.range.start.line + 1; - const end = code.range.end.line + 1; - - isInsertion = start === end; - - title += isInsertion - ? ` - Inserting at line ${start}` - : ` (${start} - ${end})`; - } - - const source = - "```" + - getMarkdownLanguageTagForFile(code.filepath) + - "\n" + - code.contents + - "\n" + - "```"; - - async function onClickFilename() { - if ("range" in code) { - await ideMessenger.ide.showLines( - code.filepath, - code.range.start.line, - code.range.end.line, - ); - } else { - await ideMessenger.ide.openFile(code.filepath); - } - } - - const smallFont = useFontSize(-3); - - const iconClass = - "text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20"; - - return ( -
-
- - Code to edit - - {/* */} -
{ - if (!isInsertion) { - setShowCodeSnippet((showCodeSnippet) => !showCodeSnippet); - } - }} - > -
- - { - e.stopPropagation(); - void onClickFilename(); - }} - > - {title} - -
- -
- { - e.stopPropagation(); - setShowCodeSnippet((val) => !val); - }} - className={`text-lightgray hover:bg-lightgray hover:text-vsc-foreground h-3.5 w-3.5 cursor-pointer rounded-sm p-0.5 hover:bg-opacity-20 ${showCodeSnippet ? "rotate-90" : ""} ${isInsertion ? "hidden" : ""}`} - /> -
- { - e.stopPropagation(); - void onDelete(); - }} - className={iconClass} - /> -
-
-
-
- {showCodeSnippet && ( -
- - - -
- )} -
- ); -} - -export default function CodeToEditCard() { - // Array from previous multi-file edit - const codeToEditArray = useAppSelector( - (state) => state.editModeState.codeToEdit, - ); - const codeToEdit = useMemo(() => { - return codeToEditArray[0]; - }, [codeToEditArray]); - - const metaKeyLabel = useMemo(() => { - return getMetaKeyLabel(); - }, []); - - const tinyFont = useFontSize(-3); - - return ( -
- {codeToEdit ? ( - - ) : ( - <> - - {`To edit code, highlight it and press `} - {metaKeyLabel} I - - - )} -
- ); -} diff --git a/gui/src/components/mainInput/ContinueInputBox.tsx b/gui/src/components/mainInput/ContinueInputBox.tsx index f3880249e..b50edfdbb 100644 --- a/gui/src/components/mainInput/ContinueInputBox.tsx +++ b/gui/src/components/mainInput/ContinueInputBox.tsx @@ -83,15 +83,15 @@ function ContinueInputBox(props: ContinueInputBoxProps) { const availableContextProviders = useAppSelector( (state) => state.config.config.contextProviders, ); - const mode = useAppSelector((store) => store.session.mode); + const isInEdit = useAppSelector((store) => store.session.isInEdit); const editModeState = useAppSelector((state) => state.editModeState); const filteredSlashCommands = useMemo(() => { - return mode === "edit" ? [] : availableSlashCommands; - }, [mode, availableSlashCommands]); + return isInEdit ? [] : availableSlashCommands; + }, [isInEdit, availableSlashCommands]); const filteredContextProviders = useMemo(() => { - if (mode === "edit") { + if (isInEdit) { return ( availableContextProviders?.filter( (provider) => @@ -101,22 +101,21 @@ function ContinueInputBox(props: ContinueInputBoxProps) { } return availableContextProviders ?? []; - }, [availableContextProviders, mode]); + }, [availableContextProviders, isInEdit]); - const historyKey = mode === "edit" ? "edit" : "chat"; - const placeholder = mode === "edit" ? "Describe changes" : undefined; + const historyKey = isInEdit ? "edit" : "chat"; + const placeholder = isInEdit ? "Edit selected code" : undefined; - const toolbarOptions: ToolbarOptions = - mode === "edit" - ? { - hideAddContext: false, - hideImageUpload: false, - hideUseCodebase: true, - hideSelectModel: false, - enterText: - editModeState.applyState.status === "done" ? "Retry" : "Edit", - } - : {}; + const toolbarOptions: ToolbarOptions = isInEdit + ? { + hideAddContext: false, + hideImageUpload: false, + hideUseCodebase: true, + hideSelectModel: false, + enterText: + editModeState.applyState.status === "done" ? "Retry" : "Edit", + } + : {}; const { appliedRules = [], contextItems = [] } = props; diff --git a/gui/src/components/mainInput/EditModeDetails.tsx b/gui/src/components/mainInput/EditModeDetails.tsx index 69746bcc2..ea95cec0a 100644 --- a/gui/src/components/mainInput/EditModeDetails.tsx +++ b/gui/src/components/mainInput/EditModeDetails.tsx @@ -1,26 +1,28 @@ import { useContext } from "react"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { exitEditMode } from "../../redux/thunks/editMode"; +import { exitEdit } from "../../redux/thunks/edit"; import AcceptRejectDiffButtons from "../AcceptRejectDiffButtons"; import { useMainEditor } from "./TipTapEditor"; const EditModeDetails = () => { const isStreaming = useAppSelector((store) => store.session.isStreaming); - const mode = useAppSelector((store) => store.session.mode); const dispatch = useAppDispatch(); const editApplyState = useAppSelector( (store) => store.editModeState.applyState, ); + const isInEdit = useAppSelector((store) => store.session.isInEdit); const { mainEditor } = useMainEditor(); const ideMessenger = useContext(IdeMessengerContext); - if (mode !== "edit") { + if (!isInEdit) { return null; } + if (isStreaming) { return null; } + if (editApplyState.status === "done") { const plural = editApplyState.numDiffs === 1 ? "" : "s"; return ( @@ -32,7 +34,7 @@ const EditModeDetails = () => { applyStates={[editApplyState]} onAcceptOrReject={async (outcome) => { if (outcome === "acceptDiff") { - await dispatch(exitEditMode({})); + await dispatch(exitEdit({})); ideMessenger.post("focusEditor", undefined); } else { mainEditor?.commands.focus(); diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 1dca2e6bc..f1d67feac 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -10,7 +10,7 @@ import { selectCurrentToolCallApplyState, } from "../../redux/selectors/selectCurrentToolCall"; import { selectSelectedChatModel } from "../../redux/slices/configSlice"; -import { exitEditMode } from "../../redux/thunks/editMode"; +import { exitEdit } from "../../redux/thunks/edit"; import { getAltKeyLabel, getMetaKeyLabel, @@ -18,7 +18,7 @@ import { } from "../../util"; import { ToolTip } from "../gui/Tooltip"; import ModelSelect from "../modelSelection/ModelSelect"; -import ModeSelect from "../modelSelection/ModeSelect"; +import { ModeSelect } from "../ModeSelect"; import { useFontSize } from "../ui/font"; import { EnterButton } from "./InputToolbar/EnterButton"; import HoverItem from "./InputToolbar/HoverItem"; @@ -49,7 +49,7 @@ function InputToolbar(props: InputToolbarProps) { const fileInputRef = useRef(null); const defaultModel = useAppSelector(selectSelectedChatModel); const useActiveFile = useAppSelector(selectUseActiveFile); - const mode = useAppSelector((store) => store.session.mode); + const isInEdit = useAppSelector((store) => store.session.isInEdit); const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit); const toolCallState = useAppSelector(selectCurrentToolCall); const currentToolCallApplyState = useAppSelector( @@ -58,7 +58,7 @@ function InputToolbar(props: InputToolbarProps) { const isEnterDisabled = props.disabled || - (mode === "edit" && codeToEdit.length === 0) || + (isInEdit && codeToEdit.length === 0) || toolCallState?.status === "generated" || (currentToolCallApplyState && currentToolCallApplyState.status !== "closed"); @@ -87,12 +87,14 @@ function InputToolbar(props: InputToolbarProps) { }} >
- - - - Select Mode - - + {!isInEdit && ( + + + + Select Mode + + + )} @@ -154,7 +156,7 @@ function InputToolbar(props: InputToolbarProps) { fontSize: tinyFont, }} > - {!props.toolbarOptions?.hideUseCodebase && mode !== "edit" && ( + {!props.toolbarOptions?.hideUseCodebase && !isInEdit && ( )} - {mode === "edit" && ( + {isInEdit && ( { - dispatch(exitEditMode({})); + void dispatch(exitEdit({})); ideMessenger.post("focusEditor", undefined); }} > - Esc to exit + Esc to exit Edit )} diff --git a/gui/src/components/mainInput/Lump/LumpToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar.tsx deleted file mode 100644 index f8953cbf7..000000000 --- a/gui/src/components/mainInput/Lump/LumpToolbar.tsx +++ /dev/null @@ -1,139 +0,0 @@ -import { useContext, useEffect } from "react"; -import { useSelector } from "react-redux"; -import styled from "styled-components"; -import { AnimatedEllipsis } from "../.."; -import { IdeMessengerContext } from "../../../context/IdeMessenger"; -import { useAppDispatch, useAppSelector } from "../../../redux/hooks"; -import { selectCurrentToolCall } from "../../../redux/selectors/selectCurrentToolCall"; -import { callCurrentTool } from "../../../redux/thunks/callCurrentTool"; -import { cancelCurrentToolCall } from "../../../redux/thunks/cancelCurrentToolCall"; -import { cancelStream } from "../../../redux/thunks/cancelStream"; -import { - getAltKeyLabel, - getFontSize, - getMetaKeyLabel, - isJetBrains, -} from "../../../util"; -import { EnterButton } from "../InputToolbar/EnterButton"; -import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar"; - -const Container = styled.div` - display: flex; - justify-content: space-between; - align-items: center; - width: 100%; -`; - -const StopButton = styled.div` - font-size: ${getFontSize() - 3}px; - padding: 2px; - padding-right: 4px; - cursor: pointer; -`; - -function GeneratingIndicator() { - return ( -
- Generating - -
- ); -} - -export function LumpToolbar() { - const dispatch = useAppDispatch(); - const ideMessenger = useContext(IdeMessengerContext); - const ttsActive = useAppSelector((state) => state.ui.ttsActive); - const isStreaming = useAppSelector((state) => state.session.isStreaming); - const jetbrains = isJetBrains(); - - const toolCallState = useSelector(selectCurrentToolCall); - - const handleKeyDown = (event: KeyboardEvent) => { - if (toolCallState?.status === "generated") { - const metaKey = event.metaKey || event.ctrlKey; - const altKey = event.altKey; - - if (metaKey && event.key === "Enter") { - event.preventDefault(); - event.stopPropagation(); - dispatch(callCurrentTool()); - } else if ((jetbrains ? altKey : metaKey) && event.key === "Backspace") { - event.preventDefault(); - event.stopPropagation(); - dispatch(cancelCurrentToolCall()); - } - } - }; - - useEffect(() => { - document.addEventListener("keydown", handleKeyDown); - return () => { - document.removeEventListener("keydown", handleKeyDown); - }; - }, [toolCallState]); - - if (ttsActive) { - return ( - - - { - ideMessenger.post("tts/kill", undefined); - }} - > - ■ Stop TTS - - - ); - } - - if (isStreaming) { - return ( - - - { - dispatch(cancelStream()); - }} - > - {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */} - {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel - - - ); - } - - if (toolCallState?.status === "generated") { - return ( - -
- Pending tool call -
- -
- dispatch(cancelCurrentToolCall())} - data-testid="reject-tool-call-button" - > - {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */} - {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel - - dispatch(callCurrentTool())} - data-testid="accept-tool-call-button" - > - {getMetaKeyLabel()} ⏎ Continue - -
-
- ); - } - - return ; -} diff --git a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/BlockSettingsTopToolbar.tsx similarity index 89% rename from gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx rename to gui/src/components/mainInput/Lump/LumpToolbar/BlockSettingsTopToolbar.tsx index eaf3771f8..af2ac99fd 100644 --- a/gui/src/components/mainInput/Lump/BlockSettingsTopToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/BlockSettingsTopToolbar.tsx @@ -10,16 +10,16 @@ import { WrenchScrewdriverIcon, } from "@heroicons/react/24/outline"; import { ReactNode } from "react"; -import { vscBadgeForeground } from "../.."; -import { useAppSelector } from "../../../redux/hooks"; -import { ToolTip } from "../../gui/Tooltip"; -import AssistantSelect from "../../modelSelection/platform/AssistantSelect"; -import { useFontSize } from "../../ui/font"; -import HoverItem from "../InputToolbar/HoverItem"; -import { useLump } from "./LumpContext"; -import { ErrorsSectionTooltip } from "./sections/errors/ErrorsSectionTooltip"; -import { McpSectionTooltip } from "./sections/mcp/MCPTooltip"; -import { ToolsSectionTooltip } from "./sections/tool-policies/ToolPoliciesSectionTooltip"; +import { vscBadgeForeground } from "../../.."; +import { useAppSelector } from "../../../../redux/hooks"; +import { ToolTip } from "../../../gui/Tooltip"; +import AssistantSelect from "../../../modelSelection/platform/AssistantSelect"; +import { useFontSize } from "../../../ui/font"; +import HoverItem from "../../InputToolbar/HoverItem"; +import { useLump } from "../LumpContext"; +import { ErrorsSectionTooltip } from "../sections/errors/ErrorsSectionTooltip"; +import { McpSectionTooltip } from "../sections/mcp/MCPTooltip"; +import { ToolsSectionTooltip } from "../sections/tool-policies/ToolPoliciesSectionTooltip"; interface BlockSettingsToolbarIcon { title: string; diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/EditToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/EditToolbar.tsx new file mode 100644 index 000000000..7ea69372c --- /dev/null +++ b/gui/src/components/mainInput/Lump/LumpToolbar/EditToolbar.tsx @@ -0,0 +1,41 @@ +import { ArrowLeftIcon } from "@heroicons/react/24/outline"; +import { useContext } from "react"; +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; +import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; +import { exitEdit } from "../../../../redux/thunks"; +import FileIcon from "../../../FileIcon"; +import { getEditFilenameAndRangeText } from "../../util"; + +export function EditToolbar() { + const dispatch = useAppDispatch(); + const ideMessenger = useContext(IdeMessengerContext); + const mode = useAppSelector((state) => state.session.mode); + const codeToEdit = useAppSelector( + (state) => state.editModeState.codeToEdit[0], + ); + + return ( +
+ { + void dispatch(exitEdit({})); + ideMessenger.post("focusEditor", undefined); + }} + > + + Back to {mode.charAt(0).toUpperCase() + mode.slice(1)} + + + + + {getEditFilenameAndRangeText(codeToEdit)} + + +
+ ); +} diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx new file mode 100644 index 000000000..aa79684b4 --- /dev/null +++ b/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx @@ -0,0 +1,10 @@ +import { AnimatedEllipsis } from "../../.."; + +export function GeneratingIndicator() { + return ( +
+ Generating + +
+ ); +} diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx new file mode 100644 index 000000000..56f14284e --- /dev/null +++ b/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx @@ -0,0 +1,62 @@ +import { useEffect } from "react"; +import { useSelector } from "react-redux"; +import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; +import { selectCurrentToolCall } from "../../../../redux/selectors/selectCurrentToolCall"; +import { + callCurrentTool, + cancelCurrentToolCall, +} from "../../../../redux/thunks"; +import { isJetBrains } from "../../../../util"; +import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar"; +import { EditToolbar } from "./EditToolbar"; +import { PendingToolCallToolbar } from "./PendingToolCallToolbar"; +import { StreamingToolbar } from "./StreamingToolbar"; +import { TtsActiveToolbar } from "./TtsActiveToolbar"; + +export function LumpToolbar() { + const dispatch = useAppDispatch(); + const ttsActive = useAppSelector((state) => state.ui.ttsActive); + const isStreaming = useAppSelector((state) => state.session.isStreaming); + const isInEdit = useAppSelector((state) => state.session.isInEdit); + const jetbrains = isJetBrains(); + const toolCallState = useSelector(selectCurrentToolCall); + + const handleKeyDown = (event: KeyboardEvent) => { + if (toolCallState?.status === "generated") { + const metaKey = event.metaKey || event.ctrlKey; + const altKey = event.altKey; + + if (metaKey && event.key === "Enter") { + event.preventDefault(); + event.stopPropagation(); + void dispatch(callCurrentTool()); + } else if ((jetbrains ? altKey : metaKey) && event.key === "Backspace") { + event.preventDefault(); + event.stopPropagation(); + void dispatch(cancelCurrentToolCall()); + } + } + }; + + useEffect(() => { + document.addEventListener("keydown", handleKeyDown); + return () => { + document.removeEventListener("keydown", handleKeyDown); + }; + }, [toolCallState]); + + if (ttsActive) { + return ; + } + if (isStreaming) { + return ; + } + if (toolCallState?.status === "generated") { + return ; + } + if (isInEdit) { + return ; + } + + return ; +} diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx new file mode 100644 index 000000000..e7df74e36 --- /dev/null +++ b/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx @@ -0,0 +1,59 @@ +import styled from "styled-components"; +import { useAppDispatch } from "../../../../redux/hooks"; +import { + callCurrentTool, + cancelCurrentToolCall, +} from "../../../../redux/thunks"; +import { + getAltKeyLabel, + getFontSize, + getMetaKeyLabel, + isJetBrains, +} from "../../../../util"; +import { EnterButton } from "../../InputToolbar/EnterButton"; + +const Container = styled.div` + display: flex; + justify-content: space-between; + align-items: center; + width: 100%; +`; + +const StopButton = styled.div` + font-size: ${getFontSize() - 3}px; + padding: 2px; + padding-right: 4px; + cursor: pointer; +`; + +export function PendingToolCallToolbar() { + const dispatch = useAppDispatch(); + const jetbrains = isJetBrains(); + + return ( + +
+ Pending tool call +
+ +
+ dispatch(cancelCurrentToolCall())} + data-testid="reject-tool-call-button" + > + {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */} + {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel + + dispatch(callCurrentTool())} + data-testid="accept-tool-call-button" + > + {getMetaKeyLabel()} ⏎ Continue + +
+
+ ); +} diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx new file mode 100644 index 000000000..e79792bec --- /dev/null +++ b/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx @@ -0,0 +1,43 @@ +import styled from "styled-components"; +import { useAppDispatch } from "../../../../redux/hooks"; +import { cancelStream } from "../../../../redux/thunks"; +import { + getAltKeyLabel, + getFontSize, + getMetaKeyLabel, + isJetBrains, +} from "../../../../util"; +import { GeneratingIndicator } from "./GeneratingIndicator"; + +const Container = styled.div` + display: flex; + justify-content: space-between; + align-items: center; + width: 100%; +`; + +const StopButton = styled.div` + font-size: ${getFontSize() - 3}px; + padding: 2px; + padding-right: 4px; + cursor: pointer; +`; + +export function StreamingToolbar() { + const dispatch = useAppDispatch(); + const jetbrains = isJetBrains(); + + return ( + + + { + void dispatch(cancelStream()); + }} + > + {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel + + + ); +} diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/TtsActiveToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/TtsActiveToolbar.tsx new file mode 100644 index 000000000..b75ec76dd --- /dev/null +++ b/gui/src/components/mainInput/Lump/LumpToolbar/TtsActiveToolbar.tsx @@ -0,0 +1,37 @@ +import { useContext } from "react"; +import styled from "styled-components"; +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; +import { getFontSize } from "../../../../util"; +import { GeneratingIndicator } from "./GeneratingIndicator"; + +const Container = styled.div` + display: flex; + justify-content: space-between; + align-items: center; + width: 100%; +`; + +const StopButton = styled.div` + font-size: ${getFontSize() - 3}px; + padding: 2px; + padding-right: 4px; + cursor: pointer; +`; + +export function TtsActiveToolbar() { + const ideMessenger = useContext(IdeMessengerContext); + + return ( + + + { + ideMessenger.post("tts/kill", undefined); + }} + > + ■ Stop TTS + + + ); +} diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/index.ts b/gui/src/components/mainInput/Lump/LumpToolbar/index.ts new file mode 100644 index 000000000..a62e11c02 --- /dev/null +++ b/gui/src/components/mainInput/Lump/LumpToolbar/index.ts @@ -0,0 +1 @@ +export * from "./LumpToolbar"; diff --git a/gui/src/components/mainInput/Lump/index.tsx b/gui/src/components/mainInput/Lump/index.tsx index 218c23b68..bdd77fdf1 100644 --- a/gui/src/components/mainInput/Lump/index.tsx +++ b/gui/src/components/mainInput/Lump/index.tsx @@ -37,7 +37,7 @@ export function Lump() { return ( -
+
void>; } -const MainEditorContext = createContext( - undefined, -); +const DEFAULTS: MainEditorContextType = { + mainEditor: null, + setMainEditor: () => {}, // noop + inputId: null, + setInputId: () => {}, // noop + onEnterRef: { current: () => {} }, // noop +}; +const MainEditorContext = createContext(DEFAULTS); /** * Provider component that maintains a reference to the main editor @@ -110,8 +115,10 @@ export const MainEditorProvider: React.FC<{ children: React.ReactNode }> = ({ */ export const useMainEditor = (): MainEditorContextType => { const context = useContext(MainEditorContext); + if (context === undefined) { throw new Error("useMainEditor must be used within a MainEditorProvider"); } + return context; }; diff --git a/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx index e9222bcbc..8948a7e46 100644 --- a/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor/TipTapEditor.tsx @@ -42,14 +42,13 @@ export function TipTapEditor(props: TipTapEditorProps) { const mainEditorContext = useMainEditor(); const ideMessenger = useContext(IdeMessengerContext); - const isOSREnabled = useIsOSREnabled(); const defaultModel = useAppSelector(selectSelectedChatModel); const isStreaming = useAppSelector((state) => state.session.isStreaming); const historyLength = useAppSelector((store) => store.session.history.length); + const isInEdit = useAppSelector((store) => store.session.isInEdit); - const mode = useAppSelector((store) => store.session.mode); const { editor, onEnterRef } = createEditorConfig({ props, ideMessenger, @@ -87,10 +86,10 @@ export function TipTapEditor(props: TipTapEditorProps) { }, [editor, props.isMainInput]); useEffect(() => { - if (mode === "edit") { + if (isInEdit) { setShouldHideToolbar(false); } - }, [mode]); + }, [isInEdit]); const editorFocusedRef = useUpdatingRef(editor?.isFocused, [editor]); @@ -150,7 +149,7 @@ export function TipTapEditor(props: TipTapEditorProps) { const handleBlur = useCallback( (e: React.FocusEvent) => { - if (mode === "edit") { + if (isInEdit) { return; } // Check if the new focus target is within our InputBoxDiv @@ -165,7 +164,7 @@ export function TipTapEditor(props: TipTapEditorProps) { setShouldHideToolbar(true); }, 100); }, - [mode, blurTimeout], + [isInEdit, blurTimeout], ); const handleFocus = useCallback(() => { @@ -213,7 +212,7 @@ export function TipTapEditor(props: TipTapEditorProps) { } setShowDragOverMsg(false); let file = event.dataTransfer.files[0]; - handleImageFile(ideMessenger, file).then((result) => { + void handleImageFile(ideMessenger, file).then((result) => { if (!editor) { return; } @@ -245,7 +244,7 @@ export function TipTapEditor(props: TipTapEditorProps) { onAddContextItem={() => insertCharacterWithWhitespace("@")} onEnter={onEnterRef.current} onImageFileSelected={(file) => { - handleImageFile(ideMessenger, file).then((result) => { + void handleImageFile(ideMessenger, file).then((result) => { if (!editor) { return; } diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index 3fea17ad4..4b50f26ea 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -23,7 +23,7 @@ import { useAppSelector } from "../../../../redux/hooks"; import { selectUseActiveFile } from "../../../../redux/selectors"; import { selectSelectedChatModel } from "../../../../redux/slices/configSlice"; import { AppDispatch } from "../../../../redux/store"; -import { exitEditMode } from "../../../../redux/thunks/editMode"; +import { exitEdit } from "../../../../redux/thunks/edit"; import { getFontSize, isJetBrains } from "../../../../util"; import * as ContinueExtensions from "../extensions"; import { TipTapEditorProps } from "../TipTapEditor"; @@ -84,6 +84,8 @@ export function createEditorConfig(options: { const mode = useAppSelector((store) => store.session.mode); const modeRef = useUpdatingRef(mode); const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit); + const isInEdit = useAppSelector((store) => store.session.isInEdit); + const isInEditRef = useUpdatingRef(isInEdit); const inSubmenuRef = useRef(undefined); const inDropdownRef = useRef(false); @@ -157,7 +159,7 @@ export function createEditorConfig(options: { for (const item of items) { const file = item.getAsFile(); file && - modelSupportsImages( + void modelSupportsImages( model.provider, model.model, model.title, @@ -269,9 +271,9 @@ export function createEditorConfig(options: { return true; } - if (modeRef.current === "edit") { - dispatch( - exitEditMode({ + if (isInEditRef.current) { + void dispatch( + exitEdit({ openNewSession: false, }), ); @@ -345,7 +347,7 @@ export function createEditorConfig(options: { if (!editor) { return; } - if (isStreaming || (codeToEdit.length === 0 && mode === "edit")) { + if (isStreaming || (codeToEdit.length === 0 && isInEdit)) { return; } @@ -362,7 +364,7 @@ export function createEditorConfig(options: { props.onEnter(json, modifiers, editor); }, - [props.onEnter, editor, props.isMainInput, codeToEdit, mode], + [props.onEnter, editor, props.isMainInput, codeToEdit, isInEdit], ); return { editor, onEnterRef }; diff --git a/gui/src/components/mainInput/util/index.ts b/gui/src/components/mainInput/util/index.ts new file mode 100644 index 000000000..5f8b4fd77 --- /dev/null +++ b/gui/src/components/mainInput/util/index.ts @@ -0,0 +1,20 @@ +import { SetCodeToEditPayload } from "core"; +import { getUriPathBasename } from "core/util/uri"; + +export * from "./handleMetaKeyIssues"; + +export function getEditFilenameAndRangeText(code: SetCodeToEditPayload) { + const fileName = getUriPathBasename(code.filepath); + let title = `${fileName}`; + + if ("range" in code) { + const start = code.range.start.line + 1; + const end = code.range.end.line + 1; + const isInsertion = start === end; + title += isInsertion + ? ` - Inserting at line ${start}` + : ` (${start} - ${end})`; + } + + return title; +} diff --git a/gui/src/components/mainInput/util/inputModifiers.ts b/gui/src/components/mainInput/util/inputModifiers.ts deleted file mode 100644 index cd16b1532..000000000 --- a/gui/src/components/mainInput/util/inputModifiers.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { InputModifiers } from "core"; - -export const defaultInputModifiers: InputModifiers = { - useCodebase: false, - noContext: true, -}; diff --git a/gui/src/components/mainInput/utils.ts b/gui/src/components/mainInput/utils.ts deleted file mode 100644 index 71565a429..000000000 --- a/gui/src/components/mainInput/utils.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { JSONContent } from "@tiptap/core"; - -export function getParagraphNodeFromString(str: string): JSONContent { - return { - type: "doc", - content: [ - { - type: "paragraph", - content: [ - { - type: "text", - text: str, - }, - ], - }, - ], - }; -} diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index 3e39d6315..287de5e45 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -6,8 +6,7 @@ import { PlusIcon, } from "@heroicons/react/24/outline"; import { useContext, useEffect, useRef, useState } from "react"; -import styled from "styled-components"; -import { defaultBorderRadius, lightGray } from ".."; +import { lightGray } from ".."; import { useAuth } from "../../context/Auth"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import AddModelForm from "../../forms/AddModelForm"; @@ -30,21 +29,6 @@ interface Option { apiKey?: string; } -const IconBase = styled.div<{ $hovered: boolean }>` - width: 1.2em; - height: 1.2em; - cursor: pointer; - padding: 4px; - border-radius: ${defaultBorderRadius}; - opacity: ${(props) => (props.$hovered ? 0.75 : 0)}; - visibility: ${(props) => (props.$hovered ? "visible" : "hidden")}; - - &:hover { - opacity: 1; - background-color: ${lightGray}33; - } -`; - function modelSelectTitle(model: any): string { if (model?.title) return model?.title; if (model?.model !== undefined && model?.model.trim() !== "") { @@ -120,12 +104,12 @@ function ModelOption({ function ModelSelect() { const dispatch = useAppDispatch(); - const mode = useAppSelector((store) => store.session.mode); + const isInEdit = useAppSelector((store) => store.session.isInEdit); const config = useAppSelector((state) => state.config.config); let selectedModel = null; let allModels = null; - if (mode === "edit") { + if (isInEdit) { allModels = config.modelsByRole.edit; selectedModel = config.selectedModelByRole.edit; } @@ -226,7 +210,7 @@ function ModelSelect() { void dispatch( updateSelectedModelByRole({ selectedProfile, - role: mode === "edit" ? "edit" : "chat", + role: isInEdit ? "edit" : "chat", modelTitle: val, }), ); diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index c3f776454..dabf7dc63 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -40,6 +40,7 @@ function ParallelListeners() { const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); const history = useAppSelector((store) => store.session.history); + const isInEdit = useAppSelector((store) => store.session.isInEdit); const selectedProfileId = useAppSelector( (store) => store.profiles.selectedProfileId, @@ -99,18 +100,18 @@ function ParallelListeners() { // Load config from the IDE useEffect(() => { - initialLoadAuthAndConfig(true); + void initialLoadAuthAndConfig(true); const interval = setInterval(() => { if (hasDoneInitialConfigLoad.current) { // Init to run on initial config load ideMessenger.post("docs/initStatuses", undefined); - dispatch(updateFileSymbolsFromHistory()); - dispatch(refreshSessionMetadata({})); + void dispatch(updateFileSymbolsFromHistory()); + void dispatch(refreshSessionMetadata({})); // This triggers sending pending status to the GUI for relevant docs indexes clearInterval(interval); } else { - initialLoadAuthAndConfig(true); + void initialLoadAuthAndConfig(true); } }, 2_000); @@ -132,39 +133,43 @@ function ParallelListeners() { const sessionId = useAppSelector((state) => state.session.id); useEffect(() => { if (sessionId) { - dispatch(updateFileSymbolsFromHistory()); + void dispatch(updateFileSymbolsFromHistory()); } }, [sessionId]); // ON LOAD useEffect(() => { // Override persisted state - dispatch(cancelStream()); + void dispatch(cancelStream()); const jetbrains = isJetBrains(); setDocumentStylesFromLocalStorage(jetbrains); if (jetbrains) { // Save theme colors to local storage for immediate loading in JetBrains - ideMessenger.request("jetbrains/getColors", undefined).then((result) => { - if (result.status === "success") { - setDocumentStylesFromTheme(result.content); - } - }); + void ideMessenger + .request("jetbrains/getColors", undefined) + .then((result) => { + if (result.status === "success") { + setDocumentStylesFromTheme(result.content); + } + }); // Tell JetBrains the webview is ready - ideMessenger.request("jetbrains/onLoad", undefined).then((result) => { - if (result.status === "error") { - return; - } + void ideMessenger + .request("jetbrains/onLoad", undefined) + .then((result) => { + if (result.status === "error") { + return; + } - const msg = result.content; - (window as any).windowId = msg.windowId; - (window as any).serverUrl = msg.serverUrl; - (window as any).workspacePaths = msg.workspacePaths; - (window as any).vscMachineId = msg.vscMachineId; - (window as any).vscMediaUrl = msg.vscMediaUrl; - }); + const msg = result.content; + (window as any).windowId = msg.windowId; + (window as any).serverUrl = msg.serverUrl; + (window as any).workspacePaths = msg.workspacePaths; + (window as any).vscMachineId = msg.vscMachineId; + (window as any).vscMediaUrl = msg.vscMediaUrl; + }); } }, []); @@ -194,7 +199,7 @@ function ParallelListeners() { ); useWebviewListener("setInactive", async () => { - dispatch(cancelStream()); + void dispatch(cancelStream()); }); useWebviewListener("setTTSActive", async (status) => { @@ -203,7 +208,7 @@ function ParallelListeners() { // TODO - remove? useWebviewListener("submitMessage", async (data) => { - dispatch( + void dispatch( streamResponseThunk({ editorState: data.message, modifiers: { useCodebase: false, noContext: true }, @@ -253,7 +258,7 @@ function ParallelListeners() { }), ); // dispatch(setToolCallOutput([])); - dispatch( + void dispatch( streamResponseAfterToolCall({ toolCallId: currentToolCallApplyState.toolCallId!, }), @@ -264,12 +269,12 @@ function ParallelListeners() { [currentToolCallApplyState, history], ); - const mode = useAppSelector((store) => store.session.mode); useEffect(() => { - if (mode !== "edit") { + if (isInEdit) { dispatch(setLastNonEditSessionEmpty(history.length === 0)); } - }, [mode, history]); + }, [isInEdit, history]); + return <>; } diff --git a/gui/src/hooks/useNavigationListener.tsx b/gui/src/hooks/useNavigationListener.tsx index 3c09dc2d0..9ff9c8ea2 100644 --- a/gui/src/hooks/useNavigationListener.tsx +++ b/gui/src/hooks/useNavigationListener.tsx @@ -8,6 +8,7 @@ const openGUITypes: (keyof ToWebviewProtocol)[] = [ "focusContinueInput", "focusContinueInputWithoutClear", "newSession", + "focusEdit", ]; export const useNavigationListener = () => { diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 71b87c93a..d73ff98b9 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -44,24 +44,23 @@ import { setDialogMessage, setShowDialog, } from "../../redux/slices/uiSlice"; -import { cancelStream } from "../../redux/thunks/cancelStream"; -import { streamEditThunk } from "../../redux/thunks/editMode"; -import { loadLastSession } from "../../redux/thunks/session"; import { streamResponseThunk } from "../../redux/thunks"; +import { cancelStream } from "../../redux/thunks/cancelStream"; +import { streamEditThunk } from "../../redux/thunks/edit"; +import { loadLastSession } from "../../redux/thunks/session"; import { isJetBrains, isMetaEquivalentKeyPressed } from "../../util"; import { FREE_TRIAL_LIMIT_REQUESTS, incrementFreeTrialCount, } from "../../util/freeTrial"; -import CodeToEditCard from "../../components/mainInput/CodeToEditCard"; +import AcceptRejectDiffButtons from "../../components/AcceptRejectDiffButtons"; import EditModeDetails from "../../components/mainInput/EditModeDetails"; import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; import { ToolCallDiv } from "./ToolCallDiv"; import { useAutoScroll } from "./useAutoScroll"; -import AcceptRejectDiffButtons from "../../components/AcceptRejectDiffButtons"; const StepsDiv = styled.div` position: relative; @@ -120,6 +119,7 @@ export function Chat() { const codeToEdit = useAppSelector((state) => state.editModeState.codeToEdit); const toolCallState = useAppSelector(selectCurrentToolCall); const mode = useAppSelector((store) => store.session.mode); + const isInEdit = useAppSelector((store) => store.session.isInEdit); const applyStates = useAppSelector( (state) => state.session.codeBlockApplyStates.states, ); @@ -142,7 +142,7 @@ export function Chat() { (jetbrains ? e.altKey : isMetaEquivalentKeyPressed(e)) && !e.shiftKey ) { - dispatch(cancelStream()); + void dispatch(cancelStream()); } }; window.addEventListener("keydown", listener); @@ -179,15 +179,14 @@ export function Chat() { ); } - const model = - mode === "edit" - ? (selectedModels?.edit ?? selectedModels?.chat) - : selectedModels?.chat; + const model = isInEdit + ? (selectedModels?.edit ?? selectedModels?.chat) + : selectedModels?.chat; if (!model) { return; } - if (mode === "edit" && codeToEdit.length === 0) { + if (isInEdit && codeToEdit.length === 0) { return; } @@ -218,15 +217,15 @@ export function Chat() { } } - if (mode === "edit") { - dispatch( + if (isInEdit) { + void dispatch( streamEditThunk({ editorState, codeToEdit, }), ); } else { - dispatch(streamResponseThunk({ editorState, modifiers, index })); + void dispatch(streamResponseThunk({ editorState, modifiers, index })); if (editorToClearOnSend) { editorToClearOnSend.commands.clearContent(); @@ -246,7 +245,15 @@ export function Chat() { setLocalStorage("mainTextEntryCounter", 1); } }, - [history, selectedModels, streamResponse, mode, codeToEdit, toolCallState], + [ + history, + selectedModels, + streamResponse, + mode, + isInEdit, + codeToEdit, + toolCallState, + ], ); useWebviewListener( @@ -288,7 +295,7 @@ export function Chat() { <> {widget} - {!!showSessionTabs && mode !== "edit" && } + {!!showSessionTabs && !isInEdit && }
<> - {!isStreaming && mode !== "edit" && ( + {!isStreaming && !isInEdit && ( {}} /> )} - {mode === "edit" && } - + {isInEdit && }
- {history.length === 0 && lastSessionId && mode !== "edit" && ( + {history.length === 0 && lastSessionId && !isInEdit && (
{ diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 627829da4..d9965920b 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -47,6 +47,7 @@ type SessionState = { mainEditorContentTrigger?: JSONContent | undefined; symbols: FileSymbolMap; mode: MessageModes; + isInEdit: boolean; codeBlockApplyStates: { states: ApplyState[]; curIndex: number; @@ -63,6 +64,7 @@ const initialState: SessionState = { streamAborter: new AbortController(), symbols: {}, mode: "chat", + isInEdit: false, codeBlockApplyStates: { states: [], curIndex: 0, @@ -645,6 +647,9 @@ export const sessionSlice = createSlice({ setMode: (state, action: PayloadAction) => { state.mode = action.payload; }, + setIsInEdit: (state, action: PayloadAction) => { + state.isInEdit = action.payload; + }, setNewestToolbarPreviewForInput: ( state, { @@ -741,6 +746,7 @@ export const { updateSessionMetadata, deleteSessionMetadata, setNewestToolbarPreviewForInput, + setIsInEdit, } = sessionSlice.actions; export const { selectIsGatheringContext } = sessionSlice.selectors; diff --git a/gui/src/redux/thunks/editMode.ts b/gui/src/redux/thunks/edit.ts similarity index 85% rename from gui/src/redux/thunks/editMode.ts rename to gui/src/redux/thunks/edit.ts index 8a7771a24..82405049f 100644 --- a/gui/src/redux/thunks/editMode.ts +++ b/gui/src/redux/thunks/edit.ts @@ -1,9 +1,9 @@ import { createAsyncThunk } from "@reduxjs/toolkit"; import { JSONContent } from "@tiptap/core"; import { - SetCodeToEditPayload, MessageModes, RangeInFileWithContents, + SetCodeToEditPayload, } from "core"; import { stripImages } from "core/util/messageContent"; import { resolveEditorContent } from "../../components/mainInput/TipTapEditor"; @@ -13,7 +13,12 @@ import { setReturnToModeAfterEdit, updateEditStateApplyState, } from "../slices/editModeState"; -import { newSession, setActive, setMode } from "../slices/sessionSlice"; +import { + newSession, + setActive, + setIsInEdit, + setMode, +} from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; import { loadLastSession, saveCurrentSession } from "./session"; import { streamThunkWrapper } from "./streamThunkWrapper"; @@ -62,17 +67,18 @@ export const streamEditThunk = createAsyncThunk< }, ); -export const exitEditMode = createAsyncThunk< +export const exitEdit = createAsyncThunk< void, { goToMode?: MessageModes; openNewSession?: boolean }, ThunkApiType >( - "edit/exitMode", + "edit/exit", async ({ goToMode, openNewSession }, { dispatch, extra, getState }) => { const state = getState(); const codeToEdit = state.editModeState.codeToEdit; + const isInEdit = state.session.isInEdit; - if (state.session.mode !== "edit") { + if (!isInEdit) { return; } @@ -86,6 +92,7 @@ export const exitEditMode = createAsyncThunk< dispatch(clearCodeToEdit()); dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE)); + dispatch(setIsInEdit(false)); if (openNewSession || state.editModeState.lastNonEditSessionWasEmpty) { dispatch(newSession()); @@ -101,14 +108,15 @@ export const exitEditMode = createAsyncThunk< }, ); -export const enterEditMode = createAsyncThunk< +export const enterEdit = createAsyncThunk< void, { returnToMode?: MessageModes }, ThunkApiType ->("edit/enterMode", async ({ returnToMode }, { dispatch, extra, getState }) => { +>("edit/enter", async ({ returnToMode }, { dispatch, extra, getState }) => { const state = getState(); + const isInEdit = state.session.isInEdit; - if (state.session.mode === "edit") { + if (isInEdit) { return; } @@ -117,12 +125,12 @@ export const enterEditMode = createAsyncThunk< await dispatch( saveCurrentSession({ openNewSession: true, - // Because this causes a lag before Edit mode is focused. TODO just have that happen in background + // Because this causes a lag before Edit is focused. TODO just have that happen in background generateTitle: false, }), ); dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE)); - dispatch(setMode("edit")); + dispatch(setIsInEdit(true)); if (!state.editModeState.codeToEdit[0]) { extra.ideMessenger.post("edit/addCurrentSelection", undefined); diff --git a/gui/src/redux/thunks/index.ts b/gui/src/redux/thunks/index.ts index 7fe098e70..81c3e937c 100644 --- a/gui/src/redux/thunks/index.ts +++ b/gui/src/redux/thunks/index.ts @@ -1,7 +1,11 @@ -export { gatherContext } from "./gatherContext"; -export { resetStateForNewMessage } from "./resetStateForNewMessage"; -export { streamNormalInput } from "./streamNormalInput"; -export { streamResponseThunk } from "./streamResponse"; -export { streamResponseAfterToolCall } from "./streamResponseAfterToolCall"; -export { streamThunkWrapper } from "./streamThunkWrapper"; -export { updateSelectedModelByRole } from "./updateSelectedModelByRole"; +export * from "./callCurrentTool"; +export * from "./cancelCurrentToolCall"; +export * from "./cancelStream"; +export * from "./edit"; +export * from "./gatherContext"; +export * from "./resetStateForNewMessage"; +export * from "./streamNormalInput"; +export * from "./streamResponse"; +export * from "./streamResponseAfterToolCall"; +export * from "./streamThunkWrapper"; +export * from "./updateSelectedModelByRole"; From fab53472a931b49d7f0c19af22263df6b54bc292 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 22 May 2025 15:39:21 -0700 Subject: [PATCH 02/11] fix: navigation bug --- gui/src/components/History/index.tsx | 2 -- gui/src/components/Layout.tsx | 1 + gui/src/components/ModeSelect/ModeIcon.tsx | 4 +--- gui/src/components/ModeSelect/ModeSelect.tsx | 4 ++-- .../components/mainInput/TipTapEditor/utils/editorConfig.ts | 2 -- gui/src/hooks/ParallelListeners.tsx | 2 +- gui/src/hooks/useNavigationListener.tsx | 1 - 7 files changed, 5 insertions(+), 11 deletions(-) diff --git a/gui/src/components/History/index.tsx b/gui/src/components/History/index.tsx index 8d96715cf..e51dc45eb 100644 --- a/gui/src/components/History/index.tsx +++ b/gui/src/components/History/index.tsx @@ -13,7 +13,6 @@ import Shortcut from "../gui/Shortcut"; import { XMarkIcon } from "@heroicons/react/24/solid"; import { useNavigate } from "react-router-dom"; import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { useNavigationListener } from "../../hooks/useNavigationListener"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { newSession, @@ -38,7 +37,6 @@ const HEADER_CLASS = "flex user-select-none pt-2 pb-3 opacity-75 text-center font-bold items-center justify-center sticky h-6"; export function History() { - useNavigationListener(); const dispatch = useAppDispatch(); const navigate = useNavigate(); const searchInputRef = React.useRef(null); diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 6a08a9f8c..2ad91f1b5 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -147,6 +147,7 @@ const Layout = () => { useWebviewListener( "focusEdit", async () => { + navigate(ROUTES.HOME); await ideMessenger.request("edit/addCurrentSelection", undefined); await dispatch(enterEdit({})); mainEditor?.commands.focus(); diff --git a/gui/src/components/ModeSelect/ModeIcon.tsx b/gui/src/components/ModeSelect/ModeIcon.tsx index 0b95ff4bc..83201d5ae 100644 --- a/gui/src/components/ModeSelect/ModeIcon.tsx +++ b/gui/src/components/ModeSelect/ModeIcon.tsx @@ -6,7 +6,7 @@ interface ModeIconProps { className?: string; } -function ModeIcon({ +export function ModeIcon({ mode, className = "xs:h-3 xs:w-3 h-3 w-3", }: ModeIconProps) { @@ -17,5 +17,3 @@ function ModeIcon({ return ; } } - -export default ModeIcon; diff --git a/gui/src/components/ModeSelect/ModeSelect.tsx b/gui/src/components/ModeSelect/ModeSelect.tsx index b0fd1eee1..331e562f2 100644 --- a/gui/src/components/ModeSelect/ModeSelect.tsx +++ b/gui/src/components/ModeSelect/ModeSelect.tsx @@ -13,7 +13,7 @@ import { ListboxOption, ListboxOptions, } from "../ui/Listbox"; -import ModeIcon from "./ModeIcon"; +import { ModeIcon } from "./ModeIcon"; export function ModeSelect() { const dispatch = useAppDispatch(); @@ -76,7 +76,7 @@ export function ModeSelect() {
diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index 4b50f26ea..774a95446 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -81,8 +81,6 @@ export function createEditorConfig(options: { const isStreaming = useAppSelector((state) => state.session.isStreaming); const useActiveFile = useAppSelector(selectUseActiveFile); const historyLength = useAppSelector((store) => store.session.history.length); - const mode = useAppSelector((store) => store.session.mode); - const modeRef = useUpdatingRef(mode); const codeToEdit = useAppSelector((store) => store.editModeState.codeToEdit); const isInEdit = useAppSelector((store) => store.session.isInEdit); const isInEditRef = useUpdatingRef(isInEdit); diff --git a/gui/src/hooks/ParallelListeners.tsx b/gui/src/hooks/ParallelListeners.tsx index dabf7dc63..216937e59 100644 --- a/gui/src/hooks/ParallelListeners.tsx +++ b/gui/src/hooks/ParallelListeners.tsx @@ -270,7 +270,7 @@ function ParallelListeners() { ); useEffect(() => { - if (isInEdit) { + if (!isInEdit) { dispatch(setLastNonEditSessionEmpty(history.length === 0)); } }, [isInEdit, history]); diff --git a/gui/src/hooks/useNavigationListener.tsx b/gui/src/hooks/useNavigationListener.tsx index 9ff9c8ea2..3c09dc2d0 100644 --- a/gui/src/hooks/useNavigationListener.tsx +++ b/gui/src/hooks/useNavigationListener.tsx @@ -8,7 +8,6 @@ const openGUITypes: (keyof ToWebviewProtocol)[] = [ "focusContinueInput", "focusContinueInputWithoutClear", "newSession", - "focusEdit", ]; export const useNavigationListener = () => { From 7c72c4af878e4b683b582e40f483551314e92873 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 22 May 2025 17:13:27 -0700 Subject: [PATCH 03/11] feat: better editor content handling in edit --- .../components/AcceptRejectDiffButtons.tsx | 41 +++++------- gui/src/components/Layout.tsx | 5 +- .../components/mainInput/EditModeDetails.tsx | 61 ------------------ gui/src/components/mainInput/InputToolbar.tsx | 4 +- .../LumpToolbar/BlockSettingsTopToolbar.tsx | 6 +- .../Lump/LumpToolbar/EditOutcomeToolbar.tsx | 34 ++++++++++ .../Lump/LumpToolbar/EditToolbar.tsx | 25 ++++---- .../Lump/LumpToolbar/GeneratingIndicator.tsx | 2 +- .../Lump/LumpToolbar/LumpToolbar.tsx | 11 ++++ .../Lump/LumpToolbar/StreamingToolbar.tsx | 2 +- .../Lump/LumpToolbar/TtsActiveToolbar.tsx | 2 +- .../useMainEditorWebviewListeners.ts | 2 +- .../components/modelSelection/ModelSelect.tsx | 2 +- .../platform/AssistantSelect.tsx | 16 ++--- gui/src/hooks/ParallelListeners.tsx | 17 +++-- gui/src/pages/gui/Chat.tsx | 2 - .../slices/{editModeState.ts => editState.ts} | 24 ++++--- gui/src/redux/store.ts | 2 +- gui/src/redux/thunks/edit.ts | 63 ++++++++++++------- 19 files changed, 162 insertions(+), 159 deletions(-) delete mode 100644 gui/src/components/mainInput/EditModeDetails.tsx create mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/EditOutcomeToolbar.tsx rename gui/src/redux/slices/{editModeState.ts => editState.ts} (73%) diff --git a/gui/src/components/AcceptRejectDiffButtons.tsx b/gui/src/components/AcceptRejectDiffButtons.tsx index 675f9147f..a6504f525 100644 --- a/gui/src/components/AcceptRejectDiffButtons.tsx +++ b/gui/src/components/AcceptRejectDiffButtons.tsx @@ -3,7 +3,7 @@ import { ApplyState } from "core"; import { useContext } from "react"; import { IdeMessengerContext } from "../context/IdeMessenger"; import { getMetaKeyLabel } from "../util"; -import { useFontSize } from "./ui/font"; +import { ToolTip } from "./gui/Tooltip"; export interface AcceptRejectAllButtonsProps { applyStates: ApplyState[]; @@ -21,8 +21,6 @@ export default function AcceptRejectAllButtons({ ); const ideMessenger = useContext(IdeMessengerContext); - const tinyFont = useFontSize(-3); - async function handleAcceptOrReject(status: AcceptOrRejectOutcome) { for (const { filepath = "", streamId } of pendingApplyStates) { ideMessenger.post(status, { @@ -40,50 +38,43 @@ export default function AcceptRejectAllButtons({ return null; } + const rejectShortcut = `${getMetaKeyLabel()}⇧⌫`; + const acceptShortcut = `${getMetaKeyLabel()}⇧⏎`; + return (
+ + +
); } diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 2ad91f1b5..b5e4ebda6 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -7,7 +7,7 @@ import { IdeMessengerContext } from "../context/IdeMessenger"; import { LocalStorageProvider } from "../context/LocalStorage"; import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; -import { setCodeToEdit } from "../redux/slices/editModeState"; +import { setCodeToEdit } from "../redux/slices/editState"; import { setShowDialog } from "../redux/slices/uiSlice"; import { enterEdit, exitEdit } from "../redux/thunks/edit"; import { saveCurrentSession } from "../redux/thunks/session"; @@ -147,9 +147,8 @@ const Layout = () => { useWebviewListener( "focusEdit", async () => { - navigate(ROUTES.HOME); await ideMessenger.request("edit/addCurrentSelection", undefined); - await dispatch(enterEdit({})); + await dispatch(enterEdit({ editorContent: mainEditor?.getJSON() })); mainEditor?.commands.focus(); }, [ideMessenger, mainEditor], diff --git a/gui/src/components/mainInput/EditModeDetails.tsx b/gui/src/components/mainInput/EditModeDetails.tsx deleted file mode 100644 index ea95cec0a..000000000 --- a/gui/src/components/mainInput/EditModeDetails.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import { useContext } from "react"; -import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { exitEdit } from "../../redux/thunks/edit"; -import AcceptRejectDiffButtons from "../AcceptRejectDiffButtons"; -import { useMainEditor } from "./TipTapEditor"; - -const EditModeDetails = () => { - const isStreaming = useAppSelector((store) => store.session.isStreaming); - const dispatch = useAppDispatch(); - const editApplyState = useAppSelector( - (store) => store.editModeState.applyState, - ); - const isInEdit = useAppSelector((store) => store.session.isInEdit); - const { mainEditor } = useMainEditor(); - const ideMessenger = useContext(IdeMessengerContext); - - if (!isInEdit) { - return null; - } - - if (isStreaming) { - return null; - } - - if (editApplyState.status === "done") { - const plural = editApplyState.numDiffs === 1 ? "" : "s"; - return ( - <> -
- {`${editApplyState.numDiffs} diff${plural} remaining`} -
- { - if (outcome === "acceptDiff") { - await dispatch(exitEdit({})); - ideMessenger.post("focusEditor", undefined); - } else { - mainEditor?.commands.focus(); - } - }} - /> - - ); - } - - // Will only still show if not all accepted - if (editApplyState.status === "closed") { - return ( -
- -
- ); - } - - // Not started/streaming - return null; -}; - -export default EditModeDetails; diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index f1d67feac..fe3cd83f0 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -101,7 +101,7 @@ function InputToolbar(props: InputToolbarProps) { Select Model -
+
{props.toolbarOptions?.hideImageUpload || (supportsImages && ( <> @@ -151,7 +151,7 @@ function InputToolbar(props: InputToolbarProps) {
-
+
store.editModeState.applyState, + ); + const { mainEditor } = useMainEditor(); + const ideMessenger = useContext(IdeMessengerContext); + + return ( +
+
+ {`${editApplyState.numDiffs} diff${editApplyState.numDiffs !== 1 ? "s" : ""}`} +
+ { + if (outcome === "acceptDiff") { + await dispatch(exitEdit({})); + ideMessenger.post("focusEditor", undefined); + } else { + mainEditor?.commands.focus(); + } + }} + /> +
+ ); +} diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/EditToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/EditToolbar.tsx index 7ea69372c..10f441be4 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/EditToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/EditToolbar.tsx @@ -3,7 +3,6 @@ import { useContext } from "react"; import { IdeMessengerContext } from "../../../../context/IdeMessenger"; import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; import { exitEdit } from "../../../../redux/thunks"; -import FileIcon from "../../../FileIcon"; import { getEditFilenameAndRangeText } from "../../util"; export function EditToolbar() { @@ -14,25 +13,23 @@ export function EditToolbar() { (state) => state.editModeState.codeToEdit[0], ); + const handleBackClick = async () => { + void dispatch(exitEdit({})); + ideMessenger.post("focusEditor", undefined); + }; + return ( -
+
{ - void dispatch(exitEdit({})); - ideMessenger.post("focusEditor", undefined); - }} + onClick={handleBackClick} > - + Back to {mode.charAt(0).toUpperCase() + mode.slice(1)} - - - + + Editing{" "} + {getEditFilenameAndRangeText(codeToEdit)} diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx index aa79684b4..f2449e48f 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx @@ -2,7 +2,7 @@ import { AnimatedEllipsis } from "../../.."; export function GeneratingIndicator() { return ( -
+
Generating
diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx index 56f14284e..36b98827c 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx @@ -8,6 +8,7 @@ import { } from "../../../../redux/thunks"; import { isJetBrains } from "../../../../util"; import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar"; +import { EditOutcomeToolbar } from "./EditOutcomeToolbar"; import { EditToolbar } from "./EditToolbar"; import { PendingToolCallToolbar } from "./PendingToolCallToolbar"; import { StreamingToolbar } from "./StreamingToolbar"; @@ -20,6 +21,9 @@ export function LumpToolbar() { const isInEdit = useAppSelector((state) => state.session.isInEdit); const jetbrains = isJetBrains(); const toolCallState = useSelector(selectCurrentToolCall); + const editApplyState = useAppSelector( + (state) => state.editModeState.applyState, + ); const handleKeyDown = (event: KeyboardEvent) => { if (toolCallState?.status === "generated") { @@ -48,13 +52,20 @@ export function LumpToolbar() { if (ttsActive) { return ; } + if (isStreaming) { return ; } + if (toolCallState?.status === "generated") { return ; } + if (isInEdit) { + if (editApplyState.status === "done") { + return ; + } + return ; } diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx index e79792bec..25388272e 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx @@ -31,7 +31,7 @@ export function StreamingToolbar() { { void dispatch(cancelStream()); }} diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/TtsActiveToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/TtsActiveToolbar.tsx index b75ec76dd..034bbf281 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/TtsActiveToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/TtsActiveToolbar.tsx @@ -25,7 +25,7 @@ export function TtsActiveToolbar() { { ideMessenger.post("tts/kill", undefined); }} diff --git a/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts b/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts index 1e6651e5f..12eef0717 100644 --- a/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts +++ b/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts @@ -3,7 +3,7 @@ import { InputModifiers } from "core"; import { rifWithContentsToContextItem } from "core/commands/util"; import { MutableRefObject } from "react"; import { useWebviewListener } from "../../../hooks/useWebviewListener"; -import { clearCodeToEdit } from "../../../redux/slices/editModeState"; +import { clearCodeToEdit } from "../../../redux/slices/editState"; import { setNewestToolbarPreviewForInput } from "../../../redux/slices/sessionSlice"; import { AppDispatch } from "../../../redux/store"; import { loadSession, saveCurrentSession } from "../../../redux/thunks/session"; diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index 287de5e45..390d7f893 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -220,7 +220,7 @@ function ModelSelect() { {modelSelectTitle(selectedModel) || "Select model"} diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index dae2136df..63254cc11 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -126,7 +126,7 @@ const AssistantSelectOption = ({ )} {isLocalProfile(profile) ? ( { e.stopPropagation(); e.preventDefault(); @@ -135,7 +135,7 @@ const AssistantSelectOption = ({ /> ) : ( { e.stopPropagation(); e.preventDefault(); @@ -242,12 +242,12 @@ export default function AssistantSelect() { return (
{ - ideMessenger.request("controlPlane/openUrl", { + void ideMessenger.request("controlPlane/openUrl", { path: "/new?type=assistant", orgSlug: currentOrg?.slug, }); }} - className="flex cursor-pointer select-none items-center gap-1 text-gray-400" + className="text-description flex cursor-pointer select-none items-center gap-1" style={{ fontSize: smallFont }} > @@ -266,7 +266,7 @@ export default function AssistantSelect() {
@@ -301,7 +301,7 @@ export default function AssistantSelect() { > @@ -339,7 +339,7 @@ export default function AssistantSelect() { onClick={session ? onNewAssistant : () => login(false)} >
{ @@ -229,14 +235,15 @@ function ParallelListeners() { dispatch(updateIndexingStatus(data)); }); - const currentToolCallApplyState = useAppSelector( - selectCurrentToolCallApplyState, - ); useWebviewListener( "updateApplyState", async (state) => { if (state.streamId === EDIT_MODE_STREAM_ID) { dispatch(updateEditStateApplyState(state)); + + if (state.status === "closed") { + dispatch(exitEdit({})); + } } else { // chat or agent dispatch(updateApplyState(state)); diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index d73ff98b9..0d6329c65 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -55,7 +55,6 @@ import { } from "../../util/freeTrial"; import AcceptRejectDiffButtons from "../../components/AcceptRejectDiffButtons"; -import EditModeDetails from "../../components/mainInput/EditModeDetails"; import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; @@ -398,7 +397,6 @@ export function Chat() { } inputId={MAIN_EDITOR_INPUT_ID} /> - {isInEdit && }
{ state.lastNonEditSessionWasEmpty = payload; }, + setPreviousModeEditorContent: ( + state, + { payload }: PayloadAction, + ) => { + state.previousModeEditorContent = payload; + }, }, selectors: {}, }); @@ -73,5 +82,6 @@ export const { setCodeToEdit, updateEditStateApplyState, setLastNonEditSessionEmpty, -} = editModeStateSlice.actions; -export default editModeStateSlice.reducer; + setPreviousModeEditorContent, +} = editStateSlice.actions; +export default editStateSlice.reducer; diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index 983f7bb6c..1e0d098f3 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -17,7 +17,7 @@ import storage from "redux-persist/lib/storage"; import { IdeMessenger, IIdeMessenger } from "../context/IdeMessenger"; import { profilesReducer } from "./slices"; import configReducer from "./slices/configSlice"; -import editModeStateReducer from "./slices/editModeState"; +import editModeStateReducer from "./slices/editState"; import indexingReducer from "./slices/indexingSlice"; import sessionReducer from "./slices/sessionSlice"; import tabsReducer from "./slices/tabsSlice"; diff --git a/gui/src/redux/thunks/edit.ts b/gui/src/redux/thunks/edit.ts index 82405049f..4471cc0b4 100644 --- a/gui/src/redux/thunks/edit.ts +++ b/gui/src/redux/thunks/edit.ts @@ -10,13 +10,15 @@ import { resolveEditorContent } from "../../components/mainInput/TipTapEditor"; import { clearCodeToEdit, INITIAL_EDIT_APPLY_STATE, + setPreviousModeEditorContent, setReturnToModeAfterEdit, updateEditStateApplyState, -} from "../slices/editModeState"; +} from "../slices/editState"; import { newSession, setActive, setIsInEdit, + setMainEditorContentTrigger, setMode, } from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; @@ -32,7 +34,7 @@ export const streamEditThunk = createAsyncThunk< ThunkApiType >( "chat/streamResponse", - async ({ editorState, codeToEdit }, { dispatch, extra, getState }) => { + async ({ editorState, codeToEdit }, { dispatch, extra }) => { await dispatch( streamThunkWrapper(async () => { dispatch(setActive()); @@ -77,6 +79,8 @@ export const exitEdit = createAsyncThunk< const state = getState(); const codeToEdit = state.editModeState.codeToEdit; const isInEdit = state.session.isInEdit; + const previousModeEditorContent = + state.editModeState.previousModeEditorContent; if (!isInEdit) { return; @@ -94,6 +98,12 @@ export const exitEdit = createAsyncThunk< dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE)); dispatch(setIsInEdit(false)); + // Restore the previous editor content if available + if (previousModeEditorContent) { + dispatch(setMainEditorContentTrigger(previousModeEditorContent)); + dispatch(setPreviousModeEditorContent(undefined)); + } + if (openNewSession || state.editModeState.lastNonEditSessionWasEmpty) { dispatch(newSession()); } else { @@ -110,29 +120,36 @@ export const exitEdit = createAsyncThunk< export const enterEdit = createAsyncThunk< void, - { returnToMode?: MessageModes }, + { returnToMode?: MessageModes; editorContent?: JSONContent }, ThunkApiType ->("edit/enter", async ({ returnToMode }, { dispatch, extra, getState }) => { - const state = getState(); - const isInEdit = state.session.isInEdit; +>( + "edit/enter", + async ({ returnToMode, editorContent }, { dispatch, extra, getState }) => { + const state = getState(); + const isInEdit = state.session.isInEdit; - if (isInEdit) { - return; - } + if (isInEdit) { + return; + } - dispatch(setReturnToModeAfterEdit(returnToMode ?? state.session.mode)); + dispatch(setMainEditorContentTrigger({})); + dispatch(setPreviousModeEditorContent(editorContent)); - await dispatch( - saveCurrentSession({ - openNewSession: true, - // Because this causes a lag before Edit is focused. TODO just have that happen in background - generateTitle: false, - }), - ); - dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE)); - dispatch(setIsInEdit(true)); + dispatch(setReturnToModeAfterEdit(returnToMode ?? state.session.mode)); + dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE)); - if (!state.editModeState.codeToEdit[0]) { - extra.ideMessenger.post("edit/addCurrentSelection", undefined); - } -}); + await dispatch( + saveCurrentSession({ + openNewSession: true, + // Because this causes a lag before Edit is focused. TODO just have that happen in background + generateTitle: false, + }), + ); + + dispatch(setIsInEdit(true)); + + if (!state.editModeState.codeToEdit[0]) { + extra.ideMessenger.post("edit/addCurrentSelection", undefined); + } + }, +); From 071ecb91eb9c627e96439b7a5be260ec446500b0 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 22 May 2025 17:41:11 -0700 Subject: [PATCH 04/11] feat: move apply accept/reject into lump --- .../components/AcceptRejectDiffButtons.tsx | 4 -- .../Lump/LumpToolbar/EditOutcomeToolbar.tsx | 2 +- .../Lump/LumpToolbar/LumpToolbar.tsx | 22 +++++++--- .../LumpToolbar/PendingApplyStatesToolbar.tsx | 44 +++++++++++++++++++ gui/src/pages/gui/Chat.tsx | 28 ++++-------- 5 files changed, 69 insertions(+), 31 deletions(-) create mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/PendingApplyStatesToolbar.tsx diff --git a/gui/src/components/AcceptRejectDiffButtons.tsx b/gui/src/components/AcceptRejectDiffButtons.tsx index a6504f525..0f3bd97ea 100644 --- a/gui/src/components/AcceptRejectDiffButtons.tsx +++ b/gui/src/components/AcceptRejectDiffButtons.tsx @@ -34,10 +34,6 @@ export default function AcceptRejectAllButtons({ } } - if (!pendingApplyStates.length) { - return null; - } - const rejectShortcut = `${getMetaKeyLabel()}⇧⌫`; const acceptShortcut = `${getMetaKeyLabel()}⇧⏎`; diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/EditOutcomeToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/EditOutcomeToolbar.tsx index 1b8aa9aaf..dc3779d22 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/EditOutcomeToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/EditOutcomeToolbar.tsx @@ -14,7 +14,7 @@ export function EditOutcomeToolbar() { const ideMessenger = useContext(IdeMessengerContext); return ( -
+
{`${editApplyState.numDiffs} diff${editApplyState.numDiffs !== 1 ? "s" : ""}`}
diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx index 36b98827c..200818427 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx @@ -10,6 +10,7 @@ import { isJetBrains } from "../../../../util"; import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar"; import { EditOutcomeToolbar } from "./EditOutcomeToolbar"; import { EditToolbar } from "./EditToolbar"; +import { PendingApplyStatesToolbar } from "./PendingApplyStatesToolbar"; import { PendingToolCallToolbar } from "./PendingToolCallToolbar"; import { StreamingToolbar } from "./StreamingToolbar"; import { TtsActiveToolbar } from "./TtsActiveToolbar"; @@ -24,6 +25,9 @@ export function LumpToolbar() { const editApplyState = useAppSelector( (state) => state.editModeState.applyState, ); + const pendingApplyStates = useAppSelector( + (state) => state.session.codeBlockApplyStates.states, + ).filter((state) => state.status === "done"); const handleKeyDown = (event: KeyboardEvent) => { if (toolCallState?.status === "generated") { @@ -49,6 +53,14 @@ export function LumpToolbar() { }; }, [toolCallState]); + if (isInEdit) { + if (editApplyState.status === "done") { + return ; + } + + return ; + } + if (ttsActive) { return ; } @@ -61,12 +73,10 @@ export function LumpToolbar() { return ; } - if (isInEdit) { - if (editApplyState.status === "done") { - return ; - } - - return ; + if (pendingApplyStates.length > 0) { + return ( + + ); } return ; diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/PendingApplyStatesToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/PendingApplyStatesToolbar.tsx new file mode 100644 index 000000000..22d03dda1 --- /dev/null +++ b/gui/src/components/mainInput/Lump/LumpToolbar/PendingApplyStatesToolbar.tsx @@ -0,0 +1,44 @@ +import { ApplyState } from "core"; +import { getUriPathBasename } from "core/util/uri"; +import AcceptRejectDiffButtons from "../../../AcceptRejectDiffButtons"; +import FileIcon from "../../../FileIcon"; + +interface PendingApplyStatesToolbarProps { + pendingApplyStates: ApplyState[]; +} + +export function PendingApplyStatesToolbar({ + pendingApplyStates, +}: PendingApplyStatesToolbarProps) { + // Group apply states by filepath + const applyStatesByFilepath = pendingApplyStates.reduce( + (acc, state) => { + const filepath = state.filepath || ""; // Use empty string as fallback + if (!acc[filepath]) { + acc[filepath] = []; + } + acc[filepath].push(state); + return acc; + }, + {} as Record, + ); + + return ( +
+ {Object.entries(applyStatesByFilepath).map(([filepath, states]) => ( +
+ {filepath && ( + + + {getUriPathBasename(filepath)} + + )} + {}} + /> +
+ ))} +
+ ); +} diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 0d6329c65..973d3126c 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -54,7 +54,6 @@ import { incrementFreeTrialCount, } from "../../util/freeTrial"; -import AcceptRejectDiffButtons from "../../components/AcceptRejectDiffButtons"; import { getLocalStorage, setLocalStorage } from "../../util/localStorage"; import { EmptyChatBody } from "./EmptyChatBody"; import { ExploreDialogWatcher } from "./ExploreDialogWatcher"; @@ -119,9 +118,6 @@ export function Chat() { const toolCallState = useAppSelector(selectCurrentToolCall); const mode = useAppSelector((store) => store.session.mode); const isInEdit = useAppSelector((store) => store.session.isInEdit); - const applyStates = useAppSelector( - (state) => state.session.codeBlockApplyStates.states, - ); const lastSessionId = useAppSelector((state) => state.session.lastSessionId); const hasDismissedExploreDialog = useAppSelector( @@ -382,22 +378,14 @@ export function Chat() { ))}
- <> - {!isStreaming && !isInEdit && ( - {}} - /> - )} - - sendInput(editorState, modifiers, undefined, editor) - } - inputId={MAIN_EDITOR_INPUT_ID} - /> - + + sendInput(editorState, modifiers, undefined, editor) + } + inputId={MAIN_EDITOR_INPUT_ID} + />
Date: Thu, 22 May 2025 18:10:19 -0700 Subject: [PATCH 05/11] fix: chat tests --- gui/src/components/ModeSelect/ModeSelect.tsx | 8 ++------ gui/src/pages/gui/Chat.test.tsx | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/gui/src/components/ModeSelect/ModeSelect.tsx b/gui/src/components/ModeSelect/ModeSelect.tsx index 331e562f2..3d0ce9bc4 100644 --- a/gui/src/components/ModeSelect/ModeSelect.tsx +++ b/gui/src/components/ModeSelect/ModeSelect.tsx @@ -38,13 +38,9 @@ export function ModeSelect() { }, [mode, agentModeSupported, dispatch, selectedModel]); const cycleMode = useCallback(() => { - if (mode === "chat" && agentModeSupported) { - dispatch(setMode("agent")); - } else { - dispatch(setMode("chat")); - } + dispatch(setMode(mode === "chat" ? "agent" : "chat")); mainEditor?.commands.focus(); - }, [mode, agentModeSupported, mainEditor]); + }, [mode, mainEditor]); const selectMode = useCallback( (newMode: MessageModes) => { diff --git a/gui/src/pages/gui/Chat.test.tsx b/gui/src/pages/gui/Chat.test.tsx index 292266ab0..626438350 100644 --- a/gui/src/pages/gui/Chat.test.tsx +++ b/gui/src/pages/gui/Chat.test.tsx @@ -35,8 +35,8 @@ describe("Chat page test", () => { ); }); - // Check that it switched to Edit mode - expect(await screen.findByText("Edit")).toBeInTheDocument(); + // Check that it switched back to Chat mode + expect(await screen.findByText("Chat")).toBeInTheDocument(); }); it.skip("should send a message and receive a response", async () => { From 74734e2e34049608e9f0d9ed11c639c41e6817f1 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Thu, 22 May 2025 18:13:34 -0700 Subject: [PATCH 06/11] Update MainEditorProvider.tsx --- .../TipTapEditor/MainEditorProvider.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/gui/src/components/mainInput/TipTapEditor/MainEditorProvider.tsx b/gui/src/components/mainInput/TipTapEditor/MainEditorProvider.tsx index 5434c25f2..ca1630886 100644 --- a/gui/src/components/mainInput/TipTapEditor/MainEditorProvider.tsx +++ b/gui/src/components/mainInput/TipTapEditor/MainEditorProvider.tsx @@ -27,14 +27,15 @@ interface MainEditorContextType { onEnterRef: React.MutableRefObject<(modifiers: InputModifiers) => void>; } -const DEFAULTS: MainEditorContextType = { +const initialState: MainEditorContextType = { mainEditor: null, - setMainEditor: () => {}, // noop + setMainEditor: () => {}, inputId: null, - setInputId: () => {}, // noop - onEnterRef: { current: () => {} }, // noop + setInputId: () => {}, + onEnterRef: { current: () => {} }, }; -const MainEditorContext = createContext(DEFAULTS); + +const MainEditorContext = createContext(initialState); /** * Provider component that maintains a reference to the main editor @@ -43,8 +44,10 @@ export const MainEditorProvider: React.FC<{ children: React.ReactNode }> = ({ children, }) => { const dispatch = useAppDispatch(); - const [mainEditor, setMainEditorInternal] = useState(null); - const [inputId, setInputId] = useState(null); + const [mainEditor, setMainEditorInternal] = useState( + initialState.mainEditor, + ); + const [inputId, setInputId] = useState(initialState.inputId); const onEnterRef = useRef<(modifiers: InputModifiers) => void>(() => {}); const editorFocusedRef = useRef(false); const historyLength = useAppSelector((store) => store.session.history.length); From 25b5b8c50b05fe872d74b60ced4a6d8569686ed6 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Fri, 23 May 2025 17:24:08 -0700 Subject: [PATCH 07/11] feat: dallins feedback --- .../mainInput/Lump/LumpToolbar/LumpToolbar.tsx | 12 +++++++----- .../mainInput/TipTapEditor/MainEditorProvider.tsx | 11 ++--------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx index 200818427..a6feb245c 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx @@ -29,8 +29,12 @@ export function LumpToolbar() { (state) => state.session.codeBlockApplyStates.states, ).filter((state) => state.status === "done"); - const handleKeyDown = (event: KeyboardEvent) => { - if (toolCallState?.status === "generated") { + useEffect(() => { + if (toolCallState?.status !== "generated") { + return; + } + + const handleKeyDown = (event: KeyboardEvent) => { const metaKey = event.metaKey || event.ctrlKey; const altKey = event.altKey; @@ -43,10 +47,8 @@ export function LumpToolbar() { event.stopPropagation(); void dispatch(cancelCurrentToolCall()); } - } - }; + }; - useEffect(() => { document.addEventListener("keydown", handleKeyDown); return () => { document.removeEventListener("keydown", handleKeyDown); diff --git a/gui/src/components/mainInput/TipTapEditor/MainEditorProvider.tsx b/gui/src/components/mainInput/TipTapEditor/MainEditorProvider.tsx index ca1630886..b35254330 100644 --- a/gui/src/components/mainInput/TipTapEditor/MainEditorProvider.tsx +++ b/gui/src/components/mainInput/TipTapEditor/MainEditorProvider.tsx @@ -116,12 +116,5 @@ export const MainEditorProvider: React.FC<{ children: React.ReactNode }> = ({ /** * Hook to access the main editor context */ -export const useMainEditor = (): MainEditorContextType => { - const context = useContext(MainEditorContext); - - if (context === undefined) { - throw new Error("useMainEditor must be used within a MainEditorProvider"); - } - - return context; -}; +export const useMainEditor = (): MainEditorContextType => + useContext(MainEditorContext); From bbfb126d5bb036239c7941330ecd3deeafe10aec Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Sun, 25 May 2025 17:39:46 -0700 Subject: [PATCH 08/11] chore: merge main --- .../Lump/LumpToolbar/GeneratingIndicator.tsx | 8 +++-- .../Lump/LumpToolbar/IsApplyingToolbar.tsx | 29 +++++++++++++++++++ .../Lump/LumpToolbar/LumpToolbar.tsx | 15 ++++++++-- .../LumpToolbar/PendingToolCallToolbar.tsx | 6 ++-- .../Lump/LumpToolbar/StreamingToolbar.tsx | 23 ++------------- .../mainInput/Lump/LumpToolbar/components.ts | 18 ++++++++++++ 6 files changed, 71 insertions(+), 28 deletions(-) create mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/IsApplyingToolbar.tsx create mode 100644 gui/src/components/mainInput/Lump/LumpToolbar/components.ts diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx index f2449e48f..48c1571b4 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/GeneratingIndicator.tsx @@ -1,9 +1,13 @@ import { AnimatedEllipsis } from "../../.."; -export function GeneratingIndicator() { +export function GeneratingIndicator({ + text = "Generating", +}: { + text?: string; +}) { return (
- Generating + {text}
); diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/IsApplyingToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/IsApplyingToolbar.tsx new file mode 100644 index 000000000..0faf43e0e --- /dev/null +++ b/gui/src/components/mainInput/Lump/LumpToolbar/IsApplyingToolbar.tsx @@ -0,0 +1,29 @@ +import { useContext } from "react"; +import { IdeMessengerContext } from "../../../../context/IdeMessenger"; +import { getAltKeyLabel, getMetaKeyLabel } from "../../../../util"; +import { Container, StopButton } from "./components"; +import { GeneratingIndicator } from "./GeneratingIndicator"; + +export const IsApplyingToolbar = () => { + const ideMessenger = useContext(IdeMessengerContext); + + const jetbrains = window.location.protocol === "jb-api:"; + + return ( + + + { + // Note that this will NOT stop generation but once apply is cancelled will show the Generating/cancel option + // Apply is prioritized because it can be more catastrophic + // Intentional to be more WYSIWYG for now + ideMessenger.post("cancelApply", undefined); + }} + > + {/* JetBrains overrides cmd+backspace, so we have to use another shortcut */} + {jetbrains ? getAltKeyLabel() : getMetaKeyLabel()} ⌫ Cancel + + + ); +}; diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx index a6feb245c..6b4fdb5ba 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/LumpToolbar.tsx @@ -10,6 +10,7 @@ import { isJetBrains } from "../../../../util"; import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar"; import { EditOutcomeToolbar } from "./EditOutcomeToolbar"; import { EditToolbar } from "./EditToolbar"; +import { IsApplyingToolbar } from "./IsApplyingToolbar"; import { PendingApplyStatesToolbar } from "./PendingApplyStatesToolbar"; import { PendingToolCallToolbar } from "./PendingToolCallToolbar"; import { StreamingToolbar } from "./StreamingToolbar"; @@ -25,9 +26,15 @@ export function LumpToolbar() { const editApplyState = useAppSelector( (state) => state.editModeState.applyState, ); - const pendingApplyStates = useAppSelector( + const applyStates = useAppSelector( (state) => state.session.codeBlockApplyStates.states, - ).filter((state) => state.status === "done"); + ); + + const pendingApplyStates = applyStates.filter( + (state) => state.status === "done", + ); + + const isApplying = applyStates.some((state) => state.status === "streaming"); useEffect(() => { if (toolCallState?.status !== "generated") { @@ -55,6 +62,10 @@ export function LumpToolbar() { }; }, [toolCallState]); + if (isApplying) { + return ; + } + if (isInEdit) { if (editApplyState.status === "done") { return ; diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx index e7df74e36..3a7da10d1 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/PendingToolCallToolbar.tsx @@ -32,13 +32,13 @@ export function PendingToolCallToolbar() { return ( -
+
Pending tool call
dispatch(cancelCurrentToolCall())} data-testid="reject-tool-call-button" > @@ -47,7 +47,7 @@ export function PendingToolCallToolbar() { dispatch(callCurrentTool())} data-testid="accept-tool-call-button" > diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx b/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx index 25388272e..aa3a6cdaf 100644 --- a/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx +++ b/gui/src/components/mainInput/Lump/LumpToolbar/StreamingToolbar.tsx @@ -1,28 +1,9 @@ -import styled from "styled-components"; import { useAppDispatch } from "../../../../redux/hooks"; import { cancelStream } from "../../../../redux/thunks"; -import { - getAltKeyLabel, - getFontSize, - getMetaKeyLabel, - isJetBrains, -} from "../../../../util"; +import { getAltKeyLabel, getMetaKeyLabel, isJetBrains } from "../../../../util"; +import { Container, StopButton } from "./components"; import { GeneratingIndicator } from "./GeneratingIndicator"; -const Container = styled.div` - display: flex; - justify-content: space-between; - align-items: center; - width: 100%; -`; - -const StopButton = styled.div` - font-size: ${getFontSize() - 3}px; - padding: 2px; - padding-right: 4px; - cursor: pointer; -`; - export function StreamingToolbar() { const dispatch = useAppDispatch(); const jetbrains = isJetBrains(); diff --git a/gui/src/components/mainInput/Lump/LumpToolbar/components.ts b/gui/src/components/mainInput/Lump/LumpToolbar/components.ts new file mode 100644 index 000000000..7b4764f19 --- /dev/null +++ b/gui/src/components/mainInput/Lump/LumpToolbar/components.ts @@ -0,0 +1,18 @@ +// TODO: Convert these to tailwind + +import styled from "styled-components"; +import { getFontSize } from "../../../../util"; + +export const Container = styled.div` + display: flex; + justify-content: space-between; + align-items: center; + width: 100%; +`; + +export const StopButton = styled.div` + font-size: ${getFontSize() - 3}px; + padding: 2px; + padding-right: 4px; + cursor: pointer; +`; From 37e2d81c923085e7c63bbb57ef3084088768b1d3 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Sun, 25 May 2025 17:48:14 -0700 Subject: [PATCH 09/11] Update Chat.tsx --- gui/src/pages/gui/Chat.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 3fc23dd3d..0e5e3383d 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -294,7 +294,7 @@ export function Chat() { return ( <> - {!!showSessionTabs && mode !== "edit" && } + {!!showSessionTabs && isInEdit && } {widget} {!!showSessionTabs && !isInEdit && } From d467745852450f83666c2992750b68957aa5de4a Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Sun, 25 May 2025 17:57:41 -0700 Subject: [PATCH 10/11] Update Chat.tsx --- gui/src/pages/gui/Chat.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 0e5e3383d..75fb48c4b 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -294,11 +294,9 @@ export function Chat() { return ( <> - {!!showSessionTabs && isInEdit && } + {!!showSessionTabs && !isInEdit && } {widget} - {!!showSessionTabs && !isInEdit && } - 0 ? "flex-1" : ""}`} From 3d407ee4a90413fdb1b0b65e85fbb26e27749438 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Sun, 25 May 2025 19:33:46 -0700 Subject: [PATCH 11/11] Update ModeSelect.tsx --- gui/src/components/ModeSelect/ModeSelect.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/src/components/ModeSelect/ModeSelect.tsx b/gui/src/components/ModeSelect/ModeSelect.tsx index 3d0ce9bc4..22a9975ca 100644 --- a/gui/src/components/ModeSelect/ModeSelect.tsx +++ b/gui/src/components/ModeSelect/ModeSelect.tsx @@ -72,7 +72,7 @@ export function ModeSelect() {