diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index d6054c6c5..174c5dfdc 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -189,12 +189,6 @@ "icon": "$(fullscreen)", "group": "Continue" }, - { - "command": "continue.toggleNewWindow", - "category": "Continue", - "title": "Open New Window", - "icon": "$(link-external)" - }, { "command": "continue.openConfigJson", "category": "Continue", @@ -458,11 +452,6 @@ "command": "continue.toggleFullScreen", "group": "navigation@3", "when": "view == continue.continueGUIView" - }, - { - "command": "continue.toggleNewWindow", - "group": "navigation@4", - "when": "view == continue.continueGUIView" } ], "editor/title": [ diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 36245b6ab..babc695e3 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -483,21 +483,12 @@ const commandsMap: ( "continue.applyCodeFromChat": () => { sidebar.webviewProtocol.request("applyCodeFromChat", undefined); }, - "continue.toggleFullScreen": ({ - newWindow, - }: { newWindow?: boolean } = {}) => { + "continue.toggleFullScreen": () => { focusGUI(); // Check if full screen is already open by checking open tabs const fullScreenTab = getFullScreenTab(); - // Check if the active editor is the Continue GUI View - if (fullScreenTab && fullScreenTab.isActive) { - //Full screen open and focused - close it - vscode.commands.executeCommand("workbench.action.closeActiveEditor"); //this will trigger the onDidDispose listener below - return; - } - if (fullScreenTab && fullScreenPanel) { //Full screen open, but not focused - focus it fullScreenPanel.reveal(); @@ -537,17 +528,7 @@ const commandsMap: ( extensionContext.subscriptions, ); - if (newWindow) { - vscode.commands.executeCommand( - "workbench.action.copyEditorToNewWindow", - ); - } - }, - "continue.toggleNewWindow": () => { - focusGUI(); - vscode.commands.executeCommand("continue.toggleFullScreen", { - newWindow: true, - }); + vscode.commands.executeCommand("workbench.action.copyEditorToNewWindow"); }, "continue.openConfigJson": () => { ide.openFile(getConfigJsonPath()); @@ -651,8 +632,8 @@ const commandsMap: ( currentStatus === StatusBarStatus.Paused ? StatusBarStatus.Enabled : currentStatus === StatusBarStatus.Disabled - ? StatusBarStatus.Paused - : StatusBarStatus.Disabled; + ? StatusBarStatus.Paused + : StatusBarStatus.Disabled; } else { // Toggle between Disabled and Enabled targetStatus = @@ -670,9 +651,6 @@ const commandsMap: ( { label: "$(screen-full) Open full screen chat (Cmd+K Cmd+M)", }, - { - label: "$(link-external) Open chat in a new window", - }, { label: quickPickStatusText(targetStatus), }, @@ -724,10 +702,6 @@ const commandsMap: ( "$(screen-full) Open full screen chat (Cmd+K Cmd+M)" ) { vscode.commands.executeCommand("continue.toggleFullScreen"); - } else if ( - selectedOption === "$(link-external) Open chat in a new window" - ) { - vscode.commands.executeCommand("continue.toggleNewWindow"); } else if (selectedOption === "$(question) Open help center") { focusGUI(); vscode.commands.executeCommand("continue.navigateTo", "/more"); diff --git a/gui/src/components/History.tsx b/gui/src/components/History.tsx deleted file mode 100644 index b930d304e..000000000 --- a/gui/src/components/History.tsx +++ /dev/null @@ -1,365 +0,0 @@ -import { PencilSquareIcon, TrashIcon } from "@heroicons/react/24/outline"; -import { SessionInfo } from "core"; -import MiniSearch from "minisearch"; -import React, { Fragment, useEffect, useState } from "react"; -import { useDispatch } from "react-redux"; -import { useNavigate } from "react-router-dom"; -import styled from "styled-components"; -import { - defaultBorderRadius, - Input, - vscBadgeBackground, - vscForeground, - vscInputBackground, -} from "."; -import ButtonWithTooltip from "./ButtonWithTooltip"; -import useHistory from "../hooks/useHistory"; -import { getFontSize } from "../util"; - -const SearchBarContainer = styled.div` - display: flex; - max-width: 500px; - padding: 0 8px 0 8px; - margin: 0 auto; - align-items: center; - justify-content: center; -`; - -const SearchBar = styled.input` - padding: 4px 8px; - border-radius: ${defaultBorderRadius}; - border: 0.5px solid #888; - outline: none; - margin: 8px auto; - display: block; - background-color: ${vscInputBackground}; - color: ${vscForeground}; - &:focus { - border: 0.5px solid ${vscBadgeBackground}; - outline: none; - } -`; - -const Tr = styled.tr` - &:hover { - background-color: ${vscInputBackground}; - } - - overflow-wrap: anywhere; - - border-bottom: 1px solid ${vscInputBackground}; - border-top: 1px solid ${vscInputBackground}; -`; - -const parseDate = (date: string): Date => { - let dateObj = new Date(date); - if (isNaN(dateObj.getTime())) { - dateObj = new Date(parseInt(date)); - } - return dateObj; -}; - -const SectionHeader = styled.tr` - display: flex; - user-select: none; - padding: 4px; - background-color: ${vscInputBackground}; - width: calc(100% - 8px); - font-weight: bold; - text-align: center; - align-items: center; - justify-content: center; - margin: 0; - position: sticky; - height: 1.5em; -`; - -function TableRow({ - session, - date, - onDelete, -}: { - session: SessionInfo; - date: Date; - onDelete: (sessionId: string) => void; -}) { - const dispatch = useDispatch(); - const navigate = useNavigate(); - const apiUrl = window.serverUrl; - const workspacePaths = window.workspacePaths || [""]; - const [hovered, setHovered] = useState(false); - const [editing, setEditing] = useState(false); - const [sessionTitleEditValue, setSessionTitleEditValue] = useState( - session.title, - ); - - const { saveSession, deleteSession, loadSession, getSession, updateSession } = - useHistory(dispatch); - - const handleKeyUp = async (e: React.KeyboardEvent) => { - if (e.key === "Enter") { - if (sessionTitleEditValue !== session.title) { - session.title = sessionTitleEditValue; - const persistedSessionInfo = await getSession(session.sessionId); - persistedSessionInfo.title = sessionTitleEditValue; - await updateSession(persistedSessionInfo); - setEditing(false); - } - } else if (e.key === "Escape") { - setEditing(false); - setSessionTitleEditValue(session.title); - } - }; - - return ( - setHovered(true)} - onMouseLeave={() => setHovered(false)} - > -
{ - // Save current session - saveSession(); - await loadSession(session.sessionId); - navigate("/"); - }} - > -
- {editing ? ( -
- titleInput && titleInput.focus()} - value={sessionTitleEditValue} - onChange={(e) => setSessionTitleEditValue(e.target.value)} - onKeyUp={(e) => handleKeyUp(e)} - onBlur={() => setEditing(false)} - /> -
- ) : ( - - {JSON.stringify(session.title).slice(1, -1)} - - )} - -
- {lastPartOfPath(session.workspaceDirectory || "")} - {!hovered && ( - - {date.toLocaleString("en-US", { - year: "2-digit", - month: "2-digit", - day: "2-digit", - hour: "numeric", - minute: "2-digit", - hour12: true, - })} - - )} -
-
- - {hovered && ( -
- { - e.stopPropagation(); - setEditing(true); - }} - > - - - { - deleteSession(session.sessionId); - onDelete(session.sessionId); - }} - > - - -
- )} -
- - ); -} - -function lastPartOfPath(path: string): string { - const sep = path.includes("/") ? "/" : "\\"; - return path.split(sep).pop() || path; -} - -export function History() { - const [sessions, setSessions] = useState([]); - const [filteredAndSortedSessions, setFilteredAndSortedSessions] = useState< - SessionInfo[] - >([]); - const apiUrl = window.serverUrl; - const workspacePaths = window.workspacePaths || []; - - const deleteSessionInUI = async (sessionId: string) => { - setSessions((prev) => - prev.filter((session) => session.sessionId !== sessionId), - ); - }; - - const searchInputRef = React.useRef(null); - - const dispatch = useDispatch(); - const { getHistory, lastSessionId } = useHistory(dispatch); - - const [minisearch, setMinisearch] = useState< - MiniSearch<{ title: string; sessionId: string }> - >( - new MiniSearch({ - fields: ["title"], - storeFields: ["title", "sessionId", "id"], - }), - ); - const [searchTerm, setSearchTerm] = useState(""); - - useEffect(() => { - const fetchSessions = async () => { - const sessions = await getHistory(); - setSessions(sessions); - minisearch.addAll( - sessions.map((session) => ({ - title: session.title, - sessionId: session.sessionId, - id: session.sessionId, - })), - ); - }; - fetchSessions(); - }, [lastSessionId]); - - useEffect(() => { - // When searchTerm is empty only show sessions from the current workspace - let filteringByWorkspace = searchTerm === ""; - - // When the searchTerm is wildcard (asterisk) then show ALL sessions, otherwise use minisearch to search for user input - const sessionIds = minisearch - .search(searchTerm === "*" ? "" : searchTerm, { - fuzzy: 0.1, - }) - .map((result) => result.id); - - setFilteredAndSortedSessions( - sessions - .filter((session) => { - if ( - !filteringByWorkspace || - typeof workspacePaths === "undefined" || - typeof session.workspaceDirectory === "undefined" - ) { - return true; - } - return workspacePaths.includes(session.workspaceDirectory); - }) - // Filter by search term - .filter((session) => { - return ( - searchTerm === "*" || - filteringByWorkspace || - sessionIds.includes(session.sessionId) - ); - }) - .sort( - (a, b) => - parseDate(b.dateCreated).getTime() - - parseDate(a.dateCreated).getTime(), - ), - ); - }, [sessions, searchTerm, minisearch]); - - const yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24); - const lastWeek = new Date(Date.now() - 1000 * 60 * 60 * 24 * 7); - const lastMonth = new Date(Date.now() - 1000 * 60 * 60 * 24 * 30); - const earlier = new Date(0); - - return ( -
- - setSearchTerm(e.target.value)} - /> - { - if (searchInputRef.current.value === "") { - searchInputRef.current.value = "*"; - setSearchTerm("*"); - } else { - searchInputRef.current.value = ""; - setSearchTerm(""); - } - }} - > - {searchTerm === "" ? "Show All" : "Clear"} - - - - {filteredAndSortedSessions.length === 0 && ( -
- No past sessions found. To start a new session, either click the "+" - button or use the keyboard shortcut: Option + Command + N -
- )} - - - - {filteredAndSortedSessions.map((session, index) => { - const prevDate = - index > 0 - ? parseDate(filteredAndSortedSessions[index - 1].dateCreated) - : earlier; - const date = parseDate(session.dateCreated); - return ( - - {index === 0 && date > yesterday && ( - Today - )} - {date < yesterday && - date > lastWeek && - prevDate > yesterday && ( - This Week - )} - {date < lastWeek && date > lastMonth && prevDate > lastWeek && ( - This Month - )} - {date < lastMonth && prevDate > lastMonth && ( - Older - )} - - - deleteSessionInUI(session.sessionId)} - > - - - ); - })} - -
-
- - All session data is saved in ~/.continue/sessions - -
- ); -} diff --git a/gui/src/components/History/HistoryTableRow.tsx b/gui/src/components/History/HistoryTableRow.tsx new file mode 100644 index 000000000..ca140c8ab --- /dev/null +++ b/gui/src/components/History/HistoryTableRow.tsx @@ -0,0 +1,128 @@ +import { PencilSquareIcon, TrashIcon } from "@heroicons/react/24/outline"; +import { SessionInfo } from "core"; +import React, { useState } from "react"; +import { useDispatch } from "react-redux"; +import { useNavigate } from "react-router-dom"; +import { Input } from ".."; +import useHistory from "../../hooks/useHistory"; +import ButtonWithTooltip from "../ButtonWithTooltip"; + +function lastPartOfPath(path: string): string { + const sep = path.includes("/") ? "/" : "\\"; + return path.split(sep).pop() || path; +} + +export function HistoryTableRow({ + session, + date, + onDelete, +}: { + session: SessionInfo; + date: Date; + onDelete: (sessionId: string) => void; +}) { + const dispatch = useDispatch(); + const navigate = useNavigate(); + + const [hovered, setHovered] = useState(false); + const [editing, setEditing] = useState(false); + const [sessionTitleEditValue, setSessionTitleEditValue] = useState( + session.title, + ); + + const { saveSession, deleteSession, loadSession, getSession, updateSession } = + useHistory(dispatch); + + const handleKeyUp = async (e: React.KeyboardEvent) => { + if (e.key === "Enter") { + if (sessionTitleEditValue !== session.title) { + session.title = sessionTitleEditValue; + const persistedSessionInfo = await getSession(session.sessionId); + persistedSessionInfo.title = sessionTitleEditValue; + await updateSession(persistedSessionInfo); + } + setEditing(false); + } else if (e.key === "Escape") { + setEditing(false); + setSessionTitleEditValue(session.title); + } + }; + + return ( + + setHovered(true)} + onMouseLeave={() => setHovered(false)} + > +
{ + // Save current session + saveSession(); + await loadSession(session.sessionId); + navigate("/"); + }} + > +
+ {editing ? ( +
+ titleInput && titleInput.focus()} + value={sessionTitleEditValue} + onChange={(e) => setSessionTitleEditValue(e.target.value)} + onKeyUp={(e) => handleKeyUp(e)} + onBlur={() => setEditing(false)} + /> +
+ ) : ( + + {JSON.stringify(session.title).slice(1, -1)} + + )} + +
+ {lastPartOfPath(session.workspaceDirectory || "")} + {/* Uncomment to show the date */} + {/* + {date.toLocaleString("en-US", { + year: "2-digit", + month: "2-digit", + day: "2-digit", + hour: "numeric", + minute: "2-digit", + hour12: true, + })} + */} +
+
+ + {hovered && !editing && ( +
+ { + e.stopPropagation(); + setEditing(true); + }} + > + + + { + deleteSession(session.sessionId); + onDelete(session.sessionId); + }} + > + + +
+ )} +
+ + + ); +} diff --git a/gui/src/components/History/index.tsx b/gui/src/components/History/index.tsx new file mode 100644 index 000000000..7ed525626 --- /dev/null +++ b/gui/src/components/History/index.tsx @@ -0,0 +1,156 @@ +import { SessionInfo } from "core"; +import MiniSearch from "minisearch"; +import React, { Fragment, useEffect, useMemo, useState } from "react"; +import { useDispatch } from "react-redux"; + +import useHistory from "../../hooks/useHistory"; +import { getFontSize } from "../../util"; +import { HistoryTableRow } from "./HistoryTableRow"; +import { XMarkIcon } from "@heroicons/react/24/solid"; + +const parseDate = (date: string): Date => { + let dateObj = new Date(date); + if (isNaN(dateObj.getTime())) { + dateObj = new Date(parseInt(date)); + } + return dateObj; +}; + +const HEADER_CLASS = + "flex user-select-none pt-2 pb-3 opacity-75 text-center font-bold items-center justify-center sticky h-6"; + +export function History() { + const [sessions, setSessions] = useState([]); + + const deleteSessionInUI = async (sessionId: string) => { + setSessions((prev) => + prev.filter((session) => session.sessionId !== sessionId), + ); + }; + + const searchInputRef = React.useRef(null); + + const dispatch = useDispatch(); + const { getHistory, lastSessionId } = useHistory(dispatch); + + const [searchTerm, setSearchTerm] = useState(""); + + const minisearch = useMemo(() => { + return new MiniSearch({ + fields: ["title"], + storeFields: ["title", "sessionId", "id"], + }); + }, []); + + useEffect(() => { + const fetchSessions = async () => { + const sessions = await getHistory(); + setSessions(sessions); + minisearch.addAll( + sessions.map((session) => ({ + title: session.title, + sessionId: session.sessionId, + id: session.sessionId, + })), + ); + }; + fetchSessions(); + }, [lastSessionId]); + + const filteredAndSortedSessions: SessionInfo[] = useMemo(() => { + const sessionIds = minisearch + .search(searchTerm, { + fuzzy: 0.1, + }) + .map((result) => result.id); + + return sessions + .filter((session) => { + return searchTerm === "" || sessionIds.includes(session.sessionId); + }) + .sort( + (a, b) => + parseDate(b.dateCreated).getTime() - + parseDate(a.dateCreated).getTime(), + ); + }, [sessions, searchTerm, minisearch]); + + const yesterday = new Date(Date.now() - 1000 * 60 * 60 * 24); + const lastWeek = new Date(Date.now() - 1000 * 60 * 60 * 24 * 7); + const lastMonth = new Date(Date.now() - 1000 * 60 * 60 * 24 * 30); + const earlier = new Date(0); + + return ( +
+
+ setSearchTerm(e.target.value)} + /> + {searchTerm && ( + { + setSearchTerm(""); + if (searchInputRef.current) { + searchInputRef.current.focus(); + } + }} + /> + )} +
+ + {filteredAndSortedSessions.length === 0 && ( +
+ No past sessions found. To start a new session, either click the "+" + button or use the keyboard shortcut: Option + Command + N +
+ )} + + + + {filteredAndSortedSessions.map((session, index) => { + const prevDate = + index > 0 + ? parseDate(filteredAndSortedSessions[index - 1].dateCreated) + : earlier; + const date = parseDate(session.dateCreated); + return ( + + {index === 0 && date > yesterday && ( + Today + )} + {date < yesterday && + date > lastWeek && + prevDate > yesterday && ( + This Week + )} + {date < lastWeek && date > lastMonth && prevDate > lastWeek && ( + This Month + )} + {date < lastMonth && prevDate > lastMonth && ( + Older + )} + + deleteSessionInUI(session.sessionId)} + /> + + ); + })} + +
+
+ + All session data is saved in ~/.continue/sessions + +
+ ); +} diff --git a/gui/src/pages/gui/index.tsx b/gui/src/pages/gui/index.tsx index 53e184027..2f37027ee 100644 --- a/gui/src/pages/gui/index.tsx +++ b/gui/src/pages/gui/index.tsx @@ -1,20 +1,14 @@ import { Chat } from "./Chat"; import { History } from "../../components/History"; -import styled from "styled-components"; -import { vscSidebarBorder } from "../../components"; - -export const Aside = styled.aside` - border-right: 1px solid ${vscSidebarBorder}; -`; export default function GUI() { return (
- -
+
diff --git a/gui/src/pages/history/HistoryHeader.tsx b/gui/src/pages/history/HistoryHeader.tsx index ec64c1377..9f7af691e 100644 --- a/gui/src/pages/history/HistoryHeader.tsx +++ b/gui/src/pages/history/HistoryHeader.tsx @@ -1,7 +1,7 @@ +import { ArrowLeftIcon } from "@heroicons/react/24/outline"; import { useNavigate } from "react-router-dom"; import { lightGray, vscBackground } from "../../components"; import { useNavigationListener } from "../../hooks/useNavigationListener"; -import { ArrowLeftIcon } from "@heroicons/react/24/outline"; import { getFontSize } from "../../util"; export const HistoryHeader = () => { @@ -10,7 +10,7 @@ export const HistoryHeader = () => { return (
)", "secondary-dark": "rgb(var(--secondary-dark) / )", + "vsc-input-background": "var(--vscode-input-background, rgb(45 45 45))", + "vsc-quick-input-background": + "var(--vscode-quickInput-background, var(--vscode-input-background, rgb(45 45 45)))", + "vsc-background": "var(--vscode-sideBar-background, rgb(30 30 30))", + "vsc-foreground": "var(--vscode-editor-foreground, #fff)", + "vsc-button-background": "var(--vscode-button-background, #1bbe84)", + "vsc-button-foreground": "var(--vscode-button-foreground, #ffffff)", + "vsc-editor-background": + "var(--vscode-editor-background, var(--vscode-sideBar-background, rgb(30 30 30)))", + "vsc-list-active-background": + "var(--vscode-list-activeSelectionBackground, #1bbe84)", + "vsc-focus-border": "var(--vscode-focus-border, #1bbe84)", + "vsc-list-active-foreground": + "var(--vscode-quickInputList-focusForeground, var(--vscode-editor-foreground))", + "vsc-input-border": "var(--vscode-input-border, #999998)", + "vsc-input-border-focus": "var(--vscode-focusBorder, #999998)", + "vsc-badge-background": "var(--vscode-badge-background, #1bbe84)", + "vsc-badge-foreground": "var(--vscode-badge-foreground, #fff)", + "vsc-sidebar-border": "var(--vscode-sideBar-border, transparent)", }, }, },