fix: selector for isSingleRangeEdit
This commit is contained in:
parent
731b54eb30
commit
badeb1c88b
6 changed files with 43 additions and 35 deletions
|
|
@ -69,11 +69,11 @@ export default function CodeToEditListItem({
|
|||
<div
|
||||
className={`hover:bg-lightgray hover:text-vsc-foreground flex justify-between rounded px-2 py-0.5 transition-colors hover:bg-opacity-20 ${showCodeSnippet && "text-vsc-foreground bg-lightgray bg-opacity-20"}`}
|
||||
>
|
||||
<div className="flex items-center gap-0.5">
|
||||
<div className="flex w-4/5 min-w-0 items-center gap-0.5">
|
||||
<FileIcon filename={code.filepath} height={"18px"} width={"18px"} />
|
||||
<div className="flex gap-1.5">
|
||||
<div className="flex min-w-0 gap-1.5">
|
||||
<span
|
||||
className="text-xs hover:underline"
|
||||
className="flex-shrink-0 text-xs hover:underline"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onClickFilename(code);
|
||||
|
|
@ -81,11 +81,14 @@ export default function CodeToEditListItem({
|
|||
>
|
||||
{title}
|
||||
</span>
|
||||
<span className="text-lightgray invisible max-w-[50%] truncate text-xs group-hover:visible">
|
||||
<span className="text-lightgray invisible flex-grow truncate text-xs group-hover:visible">
|
||||
{" "}
|
||||
{/* Added flex-grow */}
|
||||
{fileSubpath}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="invisible mt-0.5 flex gap-1.5 group-hover:visible">
|
||||
<div className={isInsertion ? "hidden" : ""}>
|
||||
{showCodeSnippet ? (
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
|
|
|
|||
|
|
@ -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")}
|
||||
>
|
||||
<XMarkIcon className="mr-1 h-4 w-4 text-red-600" />
|
||||
{hasSinglePendingApplyStates ? (
|
||||
{isSingleRangeEdit ? (
|
||||
<span>Reject ({getMetaKeyLabel()}⇧⌫)</span>
|
||||
) : (
|
||||
<>
|
||||
|
|
@ -52,7 +52,7 @@ export default function AcceptRejectAllButtons({
|
|||
onClick={() => handleAcceptOrReject("acceptDiff")}
|
||||
>
|
||||
<CheckIcon className="mr-1 h-4 w-4 text-green-600" />
|
||||
{hasSinglePendingApplyStates ? (
|
||||
{isSingleRangeEdit ? (
|
||||
<span>Accept ({getMetaKeyLabel()}⇧⏎)</span>
|
||||
) : (
|
||||
<>
|
||||
|
|
|
|||
|
|
@ -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() {
|
|||
<AcceptRejectAllButtons
|
||||
pendingApplyStates={pendingApplyStates}
|
||||
onAcceptOrReject={() => {
|
||||
dispatch(clearCodeToEdit());
|
||||
dispatch(setMode("chat"));
|
||||
loadLastSession().catch((e) =>
|
||||
console.error(`Failed to load last session: ${e}`),
|
||||
);
|
||||
|
||||
dispatch(completeEdit());
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
8
gui/src/redux/thunks/index.ts
Normal file
8
gui/src/redux/thunks/index.ts
Normal file
|
|
@ -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";
|
||||
Loading…
Add table
Reference in a new issue