{
e.preventDefault();
e.stopPropagation();
- onClickAddFileToCodeToEdit();
+ onClick();
}}
>
diff --git a/gui/src/pages/Edit/AddFileCombobox.tsx b/gui/src/pages/Edit/AddFileCombobox.tsx
new file mode 100644
index 000000000..3750a448e
--- /dev/null
+++ b/gui/src/pages/Edit/AddFileCombobox.tsx
@@ -0,0 +1,130 @@
+import { useState, useContext, useEffect, useRef } from "react";
+import {
+ ContextSubmenuItemWithProvider,
+ SubmenuContextProvidersContext,
+} from "../../context/SubmenuContextProviders";
+import { Combobox } from "@headlessui/react";
+import FileIcon from "../../components/FileIcon";
+import { useSelector } from "react-redux";
+import { RootState } from "../../redux/store";
+
+export interface AddFileComboboxProps {
+ onSelect: (filepaths: string[]) => void;
+ onEscape: () => void;
+}
+
+export default function AddFileCombobox({
+ onSelect,
+ onEscape,
+}: AddFileComboboxProps) {
+ const [query, setQuery] = useState("");
+ const [selectedFiles, setSelectedFiles] = useState<
+ ContextSubmenuItemWithProvider[]
+ >([]);
+
+ const inputRef = useRef
(null);
+ const buttonRef = useRef(null);
+ const { getSubmenuContextItems } = useContext(SubmenuContextProvidersContext);
+ const allFiles = getSubmenuContextItems("file", "");
+ const codeToEdit = useSelector(
+ (state: RootState) => state.editModeState.codeToEdit,
+ );
+ const remainingFiles = allFiles.filter(
+ (file) => !codeToEdit.find((code) => code.filepath === file.id),
+ );
+
+ useEffect(() => {
+ if (inputRef.current) {
+ inputRef.current.focus();
+ }
+ }, []);
+
+ const filteredFiles =
+ query === ""
+ ? remainingFiles
+ : remainingFiles.filter((file) =>
+ file.title.toLowerCase().includes(query.toLowerCase()),
+ );
+
+ return (
+
+
{
+ setSelectedFiles(files);
+ onSelect(files.map((file) => file.id));
+ buttonRef.current?.click();
+ }}
+ >
+ {({ open }) => (
+
+
+
{
+ if (!open) {
+ buttonRef.current?.click();
+ }
+ }}
+ onFocus={() => {
+ buttonRef.current?.click();
+ }}
+ className="bg-vsc-background border-lightgray text-vsc-foreground box-border w-full rounded border border-solid py-0.5 pl-2 focus:outline-none"
+ onChange={(event) => setQuery(event.target.value)}
+ placeholder="Type to search files..."
+ onKeyDown={(e) => {
+ if (e.key === "Escape" && !open) {
+ onEscape();
+ }
+ }}
+ />
+
+
+ {filteredFiles.length > 0 ? (
+ filteredFiles.map((file) => (
+
+ `relative flex w-full cursor-pointer px-2 py-1 text-left text-xs ${
+ active
+ ? "bg-vsc-list-active-background text-vsc-list-active-foreground"
+ : ""
+ }`
+ }
+ >
+ {({ active, selected }) => (
+
+
+
+ {file.title}
+
+
+
+ {file.description}
+
+
+ )}
+
+ ))
+ ) : (
+
+ No results
+
+ )}
+
+
+ )}
+
+
+ );
+}
diff --git a/gui/src/pages/Edit/CodeToEdit.tsx b/gui/src/pages/Edit/CodeToEdit.tsx
index 1a9d35f23..f4fe00a7a 100644
--- a/gui/src/pages/Edit/CodeToEdit.tsx
+++ b/gui/src/pages/Edit/CodeToEdit.tsx
@@ -1,16 +1,21 @@
-import { useContext } from "react";
+import { useContext, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { IdeMessengerContext } from "../../context/IdeMessenger";
-import { removeCodeToEdit } from "../../redux/slices/editModeState";
+import {
+ removeCodeToEdit,
+ addCodeToEdit,
+} from "../../redux/slices/editModeState";
import { RootState } from "../../redux/store";
import CodeToEditListItem from "./CodeToEditListItem";
-
import { CodeToEdit, RangeInFileWithContents } from "core";
import AddFileButton from "./AddFileButton";
+import AddFileCombobox from "./AddFileCombobox";
+import { XMarkIcon } from "@heroicons/react/24/outline";
export default function WorkingSet() {
const dispatch = useDispatch();
const ideMessenger = useContext(IdeMessengerContext);
+ const [showAddFileCombobox, setShowAddFileCombobox] = useState(false);
const codeToEdit = useSelector(
(state: RootState) => state.editModeState.codeToEdit,
);
@@ -38,22 +43,33 @@ export default function WorkingSet() {
}
}
- const codeToEditItems = [...codeToEdit]
- .reverse()
- .map((code, i) => (
-
- ));
+ async function onSelectFilesToAdd(filepaths: string[]) {
+ const filePromises = filepaths.map(async (filepath) => {
+ const contents = await ideMessenger.ide.readFile(filepath);
+ return { contents, filepath };
+ });
+
+ const fileResults = await Promise.all(filePromises);
+
+ for (const file of fileResults) {
+ dispatch(addCodeToEdit(file));
+ }
+ }
+
+ const codeToEditItems = codeToEdit.map((code, i) => (
+
+ ));
return (
{title}
-
+
setShowAddFileCombobox(true)} />
{codeToEdit.length > 0 && (
@@ -61,6 +77,23 @@ export default function WorkingSet() {
{codeToEditItems}
)}
+
+ {showAddFileCombobox && (
+
+
+
setShowAddFileCombobox(false)}
+ />
+
+
{
+ setShowAddFileCombobox(false);
+ }}
+ className="text-lightgray hover:bg-lightgray hover:text-vsc-foreground mb-2 h-3.5 w-3.5 cursor-pointer rounded-md rounded-sm p-0.5 hover:bg-opacity-20"
+ />
+
+ )}
);
}
diff --git a/gui/src/redux/slices/editModeState.ts b/gui/src/redux/slices/editModeState.ts
index 489bc7b41..79db2a804 100644
--- a/gui/src/redux/slices/editModeState.ts
+++ b/gui/src/redux/slices/editModeState.ts
@@ -24,13 +24,21 @@ export const editModeStateSlice = createSlice({
name: "editModeState",
initialState,
reducers: {
- addCodeToEdit: (state, { payload }: PayloadAction) => {
- const entryExists = state.codeToEdit.some((entry) =>
- isCodeToEditEqual(entry, payload),
+ addCodeToEdit: (
+ state,
+ { payload }: PayloadAction,
+ ) => {
+ const entries = Array.isArray(payload) ? payload : [payload];
+
+ const newEntries = entries.filter(
+ (entry) =>
+ !state.codeToEdit.some((existingEntry) =>
+ isCodeToEditEqual(existingEntry, entry),
+ ),
);
- if (!entryExists) {
- state.codeToEdit.push(payload);
+ if (newEntries.length > 0) {
+ state.codeToEdit.push(...newEntries);
}
},
focusEdit: (state) => {
diff --git a/gui/src/redux/slices/uiStateSlice.ts b/gui/src/redux/slices/uiStateSlice.ts
index 9a13415d3..f952b5fc9 100644
--- a/gui/src/redux/slices/uiStateSlice.ts
+++ b/gui/src/redux/slices/uiStateSlice.ts
@@ -43,12 +43,6 @@ export const uiStateSlice = createSlice({
setShowDialog: (state, action: PayloadAction) => {
state.showDialog = action.payload;
},
- setShouldAddFileForEditing: (
- state,
- action: PayloadAction,
- ) => {
- state.shouldAddFileForEditing = action.payload;
- },
},
});
@@ -57,7 +51,6 @@ export const {
setDialogMessage,
setDialogEntryOn,
setShowDialog,
- setShouldAddFileForEditing,
} = uiStateSlice.actions;
export default uiStateSlice.reducer;