edit mode cleanup
This commit is contained in:
parent
8c4c38295a
commit
c6535256ee
11 changed files with 45 additions and 78 deletions
|
|
@ -52,7 +52,7 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
|||
string | undefined,
|
||||
];
|
||||
"edit/addCurrentSelection": [undefined, void];
|
||||
"edit/clearDecorations": [{ shouldFocusEditor: boolean }, void];
|
||||
"edit/clearDecorations": [undefined, void];
|
||||
};
|
||||
|
||||
export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
||||
|
|
|
|||
|
|
@ -230,15 +230,8 @@ export class VsCodeMessenger {
|
|||
});
|
||||
return fileAfterEdit;
|
||||
});
|
||||
|
||||
this.onWebview("edit/clearDecorations", async (msg) => {
|
||||
if (msg.data.shouldFocusEditor) {
|
||||
const activeEditor = vscode.window.activeTextEditor;
|
||||
|
||||
if (activeEditor) {
|
||||
vscode.window.showTextDocument(activeEditor.document);
|
||||
}
|
||||
}
|
||||
|
||||
editDecorationManager.clear();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -161,7 +161,6 @@ const Layout = () => {
|
|||
dispatch(
|
||||
setCodeToEdit({
|
||||
codeToEdit: payload,
|
||||
fromEditor: true,
|
||||
}),
|
||||
);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -36,9 +36,7 @@ function CodeToEditItem({ code }: CodeToEditItemProps) {
|
|||
|
||||
function onDelete() {
|
||||
dispatch(clearCodeToEdit());
|
||||
ideMessenger.post("edit/clearDecorations", {
|
||||
shouldFocusEditor: false,
|
||||
});
|
||||
ideMessenger.post("edit/clearDecorations", undefined);
|
||||
}
|
||||
|
||||
const fileName = getUriPathBasename(code.filepath);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { useContext } from "react";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { exitEditMode } from "../../redux/thunks/editMode";
|
||||
import AcceptRejectAllButtons from "../AcceptRejectAllButtons";
|
||||
|
|
@ -10,7 +12,8 @@ const EditModeDetails = () => {
|
|||
const editApplyState = useAppSelector(
|
||||
(store) => store.editModeState.applyState,
|
||||
);
|
||||
const mainEditor = useMainEditor();
|
||||
const { mainEditor } = useMainEditor();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
|
||||
if (mode !== "edit") {
|
||||
return null;
|
||||
|
|
@ -30,8 +33,9 @@ const EditModeDetails = () => {
|
|||
onAcceptOrReject={async (outcome) => {
|
||||
if (outcome === "acceptDiff") {
|
||||
await dispatch(exitEditMode({}));
|
||||
ideMessenger.post("focusEditor", undefined);
|
||||
} else {
|
||||
mainEditor.mainEditor?.commands.focus();
|
||||
mainEditor?.commands.focus();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { AtSymbolIcon, PhotoIcon } from "@heroicons/react/24/outline";
|
||||
import { InputModifiers } from "core";
|
||||
import { modelSupportsImages, modelSupportsTools } from "core/llm/autodetect";
|
||||
import { useRef } from "react";
|
||||
import { useContext, useRef } from "react";
|
||||
import { IdeMessengerContext } from "../../context/IdeMessenger";
|
||||
import { useAppDispatch, useAppSelector } from "../../redux/hooks";
|
||||
import { selectUseActiveFile } from "../../redux/selectors";
|
||||
import {
|
||||
|
|
@ -44,6 +45,7 @@ interface InputToolbarProps {
|
|||
|
||||
function InputToolbar(props: InputToolbarProps) {
|
||||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const fileInputRef = useRef<HTMLInputElement | null>(null);
|
||||
const defaultModel = useAppSelector(selectSelectedChatModel);
|
||||
const useActiveFile = useAppSelector(selectUseActiveFile);
|
||||
|
|
@ -187,6 +189,7 @@ function InputToolbar(props: InputToolbarProps) {
|
|||
className="hidden hover:underline sm:flex"
|
||||
onClick={async () => {
|
||||
dispatch(exitEditMode({}));
|
||||
ideMessenger.post("focusEditor", undefined);
|
||||
}}
|
||||
>
|
||||
<span>
|
||||
|
|
|
|||
|
|
@ -156,16 +156,6 @@ export function useMainEditorWebviewListeners({
|
|||
[editor, inputId, onEnterRef.current],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
"focusEdit",
|
||||
async () => {
|
||||
setTimeout(() => {
|
||||
editor?.commands.focus("end");
|
||||
}, 20);
|
||||
},
|
||||
[editor],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
"isContinueInputFocused",
|
||||
async () => {
|
||||
|
|
|
|||
|
|
@ -260,21 +260,24 @@ export function createEditorConfig(options: {
|
|||
return false;
|
||||
},
|
||||
Escape: () => {
|
||||
if (inDropdownRef.current) {
|
||||
return false;
|
||||
}
|
||||
// In JetBrains, this is how we close the sidebar when the input box is focused
|
||||
if (isJetBrains()) {
|
||||
ideMessenger.post("closeSidebar", undefined);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (inDropdownRef.current || modeRef.current !== "edit") {
|
||||
ideMessenger.post("focusEditor", undefined);
|
||||
return true;
|
||||
if (modeRef.current !== "edit") {
|
||||
} else {
|
||||
dispatch(
|
||||
exitEditMode({
|
||||
openNewSession: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
dispatch(
|
||||
exitEditMode({
|
||||
openNewSession: false,
|
||||
}),
|
||||
);
|
||||
ideMessenger.post("focusEditor", undefined);
|
||||
|
||||
return true;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -81,7 +81,6 @@ function ModeSelect() {
|
|||
await dispatch(
|
||||
enterEditMode({
|
||||
returnToMode: mode,
|
||||
returnCursorToEditor: false,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
|
|
@ -101,7 +100,6 @@ function ModeSelect() {
|
|||
await dispatch(
|
||||
enterEditMode({
|
||||
returnToMode: mode,
|
||||
returnCursorToEditor: false,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ export interface EditModeState {
|
|||
// Keeping array to not break persisted redux for now
|
||||
codeToEdit: CodeToEdit[];
|
||||
applyState: ApplyState;
|
||||
returnCursorToEditorAfterEdit: boolean;
|
||||
returnToMode: MessageModes;
|
||||
lastNonEditSessionWasEmpty: boolean;
|
||||
}
|
||||
|
|
@ -19,7 +18,6 @@ export const INITIAL_EDIT_APPLY_STATE: ApplyState = {
|
|||
const initialState: EditModeState = {
|
||||
applyState: INITIAL_EDIT_APPLY_STATE,
|
||||
codeToEdit: [],
|
||||
returnCursorToEditorAfterEdit: false,
|
||||
returnToMode: "chat",
|
||||
lastNonEditSessionWasEmpty: false,
|
||||
};
|
||||
|
|
@ -28,12 +26,6 @@ export const editModeStateSlice = createSlice({
|
|||
name: "editModeState",
|
||||
initialState,
|
||||
reducers: {
|
||||
setReturnCursorToEditorAfterEdit: (
|
||||
state,
|
||||
{ payload }: PayloadAction<boolean>,
|
||||
) => {
|
||||
state.returnCursorToEditorAfterEdit = payload;
|
||||
},
|
||||
setReturnToModeAfterEdit: (
|
||||
state,
|
||||
{ payload }: PayloadAction<MessageModes>,
|
||||
|
|
@ -54,11 +46,9 @@ export const editModeStateSlice = createSlice({
|
|||
{
|
||||
payload,
|
||||
}: PayloadAction<{
|
||||
fromEditor: boolean;
|
||||
codeToEdit: CodeToEdit | CodeToEdit[];
|
||||
}>,
|
||||
) => {
|
||||
state.returnCursorToEditorAfterEdit = payload.fromEditor;
|
||||
state.codeToEdit = Array.isArray(payload.codeToEdit)
|
||||
? payload.codeToEdit
|
||||
: [payload.codeToEdit];
|
||||
|
|
@ -78,7 +68,6 @@ export const editModeStateSlice = createSlice({
|
|||
|
||||
export const {
|
||||
setReturnToModeAfterEdit,
|
||||
setReturnCursorToEditorAfterEdit,
|
||||
clearCodeToEdit,
|
||||
setCodeToEdit,
|
||||
updateEditStateApplyState,
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ import { resolveEditorContent } from "../../components/mainInput/TipTapEditor";
|
|||
import {
|
||||
clearCodeToEdit,
|
||||
INITIAL_EDIT_APPLY_STATE,
|
||||
setReturnCursorToEditorAfterEdit,
|
||||
setReturnToModeAfterEdit,
|
||||
updateEditStateApplyState,
|
||||
} from "../slices/editModeState";
|
||||
|
|
@ -79,9 +78,7 @@ export const exitEditMode = createAsyncThunk<
|
|||
});
|
||||
}
|
||||
|
||||
extra.ideMessenger.post("edit/clearDecorations", {
|
||||
shouldFocusEditor: state.editModeState.returnCursorToEditorAfterEdit,
|
||||
});
|
||||
extra.ideMessenger.post("edit/clearDecorations", undefined);
|
||||
|
||||
dispatch(clearCodeToEdit());
|
||||
dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE));
|
||||
|
|
@ -102,35 +99,28 @@ export const exitEditMode = createAsyncThunk<
|
|||
|
||||
export const enterEditMode = createAsyncThunk<
|
||||
void,
|
||||
{ returnToMode?: MessageModes; returnCursorToEditor?: boolean },
|
||||
{ returnToMode?: MessageModes },
|
||||
ThunkApiType
|
||||
>(
|
||||
"edit/enterMode",
|
||||
async (
|
||||
{ returnCursorToEditor, returnToMode },
|
||||
{ dispatch, extra, getState },
|
||||
) => {
|
||||
const state = getState();
|
||||
>("edit/enterMode", async ({ returnToMode }, { dispatch, extra, getState }) => {
|
||||
const state = getState();
|
||||
|
||||
if (state.session.mode === "edit") {
|
||||
return;
|
||||
}
|
||||
if (state.session.mode === "edit") {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(setReturnToModeAfterEdit(returnToMode ?? state.session.mode));
|
||||
dispatch(setReturnCursorToEditorAfterEdit(returnCursorToEditor ?? false));
|
||||
dispatch(setReturnToModeAfterEdit(returnToMode ?? state.session.mode));
|
||||
|
||||
await dispatch(
|
||||
saveCurrentSession({
|
||||
openNewSession: true,
|
||||
// Because this causes a lag before Edit mode is focused. TODO just have that happen in background
|
||||
generateTitle: false,
|
||||
}),
|
||||
);
|
||||
dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE));
|
||||
dispatch(setMode("edit"));
|
||||
await dispatch(
|
||||
saveCurrentSession({
|
||||
openNewSession: true,
|
||||
// Because this causes a lag before Edit mode is focused. TODO just have that happen in background
|
||||
generateTitle: false,
|
||||
}),
|
||||
);
|
||||
dispatch(updateEditStateApplyState(INITIAL_EDIT_APPLY_STATE));
|
||||
dispatch(setMode("edit"));
|
||||
|
||||
if (!state.editModeState.codeToEdit[0]) {
|
||||
extra.ideMessenger.post("edit/addCurrentSelection", undefined);
|
||||
}
|
||||
},
|
||||
);
|
||||
if (!state.editModeState.codeToEdit[0]) {
|
||||
extra.ideMessenger.post("edit/addCurrentSelection", undefined);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue