diff --git a/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx b/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx index 7627ce5c7..59f630c9a 100644 --- a/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx +++ b/gui/src/components/CodeToEditCard/CodeToEditListItem.tsx @@ -69,11 +69,11 @@ export default function CodeToEditListItem({
-
+
-
+
{ e.stopPropagation(); onClickFilename(code); @@ -81,11 +81,14 @@ export default function CodeToEditListItem({ > {title} - + + {" "} + {/* Added flex-grow */} {fileSubpath}
+
{showCodeSnippet ? ( diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index ae264fef0..35ddea331 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -1,22 +1,16 @@ import { useEffect, useMemo } from "react"; -import { useDispatch } from "react-redux"; import { Outlet, useLocation, useNavigate } from "react-router-dom"; import styled from "styled-components"; import { CustomScrollbarDiv, defaultBorderRadius } from "."; import { LastSessionProvider } from "../context/LastSessionContext"; import { useWebviewListener } from "../hooks/useWebviewListener"; -import { useAppSelector } from "../redux/hooks"; -import { - setEditDone, - setEditStatus, - focusEdit, -} from "../redux/slices/editModeState"; +import { useAppDispatch, useAppSelector } from "../redux/hooks"; +import { setEditStatus, focusEdit } from "../redux/slices/editModeState"; import { setDialogMessage, setShowDialog } from "../redux/slices/uiSlice"; import { addCodeToEdit, updateApplyState, setMode, - clearCodeToEdit, } from "../redux/slices/sessionSlice"; import { getFontSize, isMetaEquivalentKeyPressed } from "../util"; import { getLocalStorage, setLocalStorage } from "../util/localStorage"; @@ -28,6 +22,7 @@ import PostHogPageView from "./PosthogPageView"; import AccountDialog from "./AccountDialog"; import { AuthProvider } from "../context/Auth"; import useHistory from "../hooks/useHistory"; +import { completeEdit } from "../redux/thunks"; const LayoutTopDiv = styled(CustomScrollbarDiv)` height: 100%; @@ -56,7 +51,7 @@ const GridDiv = styled.div` const Layout = () => { const navigate = useNavigate(); const location = useLocation(); - const dispatch = useDispatch(); + const dispatch = useAppDispatch(); const onboardingCard = useOnboardingCard(); const { pathname } = useLocation(); const { saveSession } = useHistory(dispatch); @@ -194,15 +189,9 @@ const Layout = () => { [], ); - useWebviewListener( - "exitEditMode", - async () => { - dispatch(setEditDone()); - dispatch(setMode("chat")); - dispatch(clearCodeToEdit()); - }, - [navigate], - ); + useWebviewListener("exitEditMode", async () => { + dispatch(completeEdit()); + }); useEffect(() => { const handleKeyDown = (event: any) => { diff --git a/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx b/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx index 632468a65..bc287c5c2 100644 --- a/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx +++ b/gui/src/components/StepContainer/AcceptRejectAllButtons.tsx @@ -3,6 +3,8 @@ import { IdeMessengerContext } from "../../context/IdeMessenger"; import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline"; import { ApplyState } from "core"; import { getMetaKeyLabel } from "../../util"; +import { useAppSelector } from "../../redux/hooks"; +import { selectIsSingleRangeEdit } from "../../redux/slices/sessionSlice"; export interface AcceptRejectAllButtonsProps { pendingApplyStates: ApplyState[]; @@ -14,9 +16,7 @@ export default function AcceptRejectAllButtons({ onAcceptOrReject, }: AcceptRejectAllButtonsProps) { const ideMessenger = useContext(IdeMessengerContext); - - // To handle the case of a single-range edit - const hasSinglePendingApplyStates = pendingApplyStates.length === 1; + const isSingleRangeEdit = useAppSelector(selectIsSingleRangeEdit); async function handleAcceptOrReject(status: "acceptDiff" | "rejectDiff") { for (const { filepath, streamId } of pendingApplyStates) { @@ -37,7 +37,7 @@ export default function AcceptRejectAllButtons({ onClick={() => handleAcceptOrReject("rejectDiff")} > - {hasSinglePendingApplyStates ? ( + {isSingleRangeEdit ? ( Reject ({getMetaKeyLabel()}⇧⌫) ) : ( <> @@ -52,7 +52,7 @@ export default function AcceptRejectAllButtons({ onClick={() => handleAcceptOrReject("acceptDiff")} > - {hasSinglePendingApplyStates ? ( + {isSingleRangeEdit ? ( Accept ({getMetaKeyLabel()}⇧⏎) ) : ( <> diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 7b871ec0e..aae4bd80a 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -40,6 +40,7 @@ import { clearLastEmptyResponse, newSession, selectIsInEditMode, + selectIsSingleRangeEdit, setInactive, setMode, } from "../../redux/slices/sessionSlice"; @@ -160,6 +161,7 @@ export function Chat() { ); const hasPendingApplies = pendingApplyStates.length > 0; const isInEditMode = useAppSelector(selectIsInEditMode); + const isSingleRangeEdit = useAppSelector(selectIsSingleRangeEdit); const snapToBottom = useCallback(() => { if (!stepsDivRef.current) return; @@ -184,10 +186,6 @@ export function Chat() { ? "Back to Chat" : "Last Session"; - const isSingleRangeEdit = - codeToEdit.length === 0 || - (codeToEdit.length === 1 && "range" in codeToEdit[0]); - useEffect(() => { if (active) snapToBottom(); }, [active, snapToBottom]); @@ -518,11 +516,11 @@ export function Chat() { { - dispatch(clearCodeToEdit()); - dispatch(setMode("chat")); loadLastSession().catch((e) => console.error(`Failed to load last session: ${e}`), ); + + dispatch(completeEdit()); }} /> )} diff --git a/gui/src/redux/slices/sessionSlice.ts b/gui/src/redux/slices/sessionSlice.ts index 592ad1232..f11f58dcb 100644 --- a/gui/src/redux/slices/sessionSlice.ts +++ b/gui/src/redux/slices/sessionSlice.ts @@ -506,6 +506,13 @@ export const sessionSlice = createSlice({ selectIsInEditMode: (state) => { return state.mode === "edit"; }, + selectIsSingleRangeEdit: (state) => { + return ( + state.mode === "edit" && + (state.codeToEdit.length === 0 || + (state.codeToEdit.length === 1 && "range" in state.codeToEdit[0])) + ); + }, }, extraReducers: (builder) => { addPassthroughCases(builder, [streamResponseThunk]); @@ -575,7 +582,10 @@ export const { setMode, } = sessionSlice.actions; -export const { selectIsGatheringContext, selectIsInEditMode } = - sessionSlice.selectors; +export const { + selectIsGatheringContext, + selectIsInEditMode, + selectIsSingleRangeEdit, +} = sessionSlice.selectors; export default sessionSlice.reducer; diff --git a/gui/src/redux/thunks/index.ts b/gui/src/redux/thunks/index.ts new file mode 100644 index 000000000..fda8d375d --- /dev/null +++ b/gui/src/redux/thunks/index.ts @@ -0,0 +1,8 @@ +export { completeEdit } from "./completeEdit"; +export { gatherContext } from "./gatherContext"; +export { handleErrors } from "./handleErrors"; +export { resetStateForNewMessage } from "./resetStateForNewMessage"; +export { streamNormalInput } from "./streamNormalInput"; +export { streamResponseThunk } from "./streamResponse"; +export { streamResponseAfterToolCall } from "./streamResponseAfterToolCall"; +export { streamSlashCommand } from "./streamSlashCommand";