From ca6770833c2ec17c36ca946e6b00ff40aab783ec Mon Sep 17 00:00:00 2001 From: Nate Date: Fri, 1 Nov 2024 21:41:03 -0700 Subject: [PATCH] sync accept/reject with edit sidebar --- .../vscode/src/extension/VsCodeMessenger.ts | 2 +- gui/src/pages/edit.tsx | 16 ++++++++++++++++ gui/src/redux/slices/uiStateSlice.ts | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index bead27f69..483ff1603 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -281,7 +281,7 @@ export class VsCodeMessenger { await verticalDiffManager.streamEdit( stripImages(prompt), modelTitle, - undefined, + "edit", undefined, undefined, new vscode.Range( diff --git a/gui/src/pages/edit.tsx b/gui/src/pages/edit.tsx index 475a293c9..f05648875 100644 --- a/gui/src/pages/edit.tsx +++ b/gui/src/pages/edit.tsx @@ -79,6 +79,7 @@ function Edit() { const [showCode, setShowCode] = useState(false); + // Reusing the applyState logic which was just the fastest way to get this working useEffect(() => { if (editModeState.editStatus === "done") { ideMessenger.request("edit/escape", undefined); @@ -86,6 +87,18 @@ function Edit() { } }, [editModeState.editStatus]); + const applyState = useSelector( + (store: RootState) => + store.uiState.applyStates.find((state) => state.streamId === "edit") + ?.status ?? "closed", + ); + + useEffect(() => { + if (applyState === "closed" && editModeState.editStatus === "accepting") { + dispatch(dispatch(setEditDone())); + } + }, [applyState, editModeState.editStatus]); + return ( <> @@ -178,6 +191,9 @@ function Edit() { range: editModeState.highlightedCode, }); dispatch(submitEdit(prompt)); + + // Move cursor to end of editor (it's already focused) + editor.commands.selectTextblockEnd(); }} > diff --git a/gui/src/redux/slices/uiStateSlice.ts b/gui/src/redux/slices/uiStateSlice.ts index 1625110eb..b3b372ccc 100644 --- a/gui/src/redux/slices/uiStateSlice.ts +++ b/gui/src/redux/slices/uiStateSlice.ts @@ -11,6 +11,10 @@ type UiState = { dialogEntryOn: boolean; nextCodeBlockToApplyIndex: number; onboardingCard: OnboardingCardState; + + /** + * Syncs the sidebar with the accepted/rejected blocks in the editor. Reused for Edit as well. + */ applyStates: ApplyState[]; };