Merge pull request #2788 from continuedev/nate/cmd-i-sidebar-v2
Cmd+I sidebar experiment
This commit is contained in:
commit
b554b1b141
23 changed files with 4111 additions and 207 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import type { RangeInFileWithContents } from "../commands/util.js";
|
||||
import type { ContextSubmenuItem } from "../index.js";
|
||||
import type { ContextSubmenuItem, MessageContent } from "../index.js";
|
||||
import { ToIdeFromWebviewOrCoreProtocol } from "./ide.js";
|
||||
import { ToWebviewFromIdeOrCoreProtocol } from "./webview.js";
|
||||
|
||||
|
|
@ -35,8 +35,23 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
|||
setGitHubAuthToken: [{ token: string }, void];
|
||||
acceptDiff: [{ filepath: string }, void];
|
||||
rejectDiff: [{ filepath: string }, void];
|
||||
"edit/sendPrompt": [
|
||||
{ prompt: MessageContent; range: RangeInFileWithContents },
|
||||
void,
|
||||
];
|
||||
"edit/acceptReject": [
|
||||
{ accept: boolean; onlyFirst: boolean; filepath: string },
|
||||
void,
|
||||
];
|
||||
"edit/escape": [undefined, void];
|
||||
};
|
||||
|
||||
export interface EditModeArgs {
|
||||
highlightedCode: RangeInFileWithContents;
|
||||
}
|
||||
|
||||
export type EditStatus = "not-started" | "streaming" | "accepting" | "done";
|
||||
|
||||
export interface ApplyState {
|
||||
streamId: string;
|
||||
status: "streaming" | "done" | "closed";
|
||||
|
|
@ -82,4 +97,7 @@ export type ToWebviewFromIdeProtocol = ToWebviewFromIdeOrCoreProtocol & {
|
|||
openOnboardingCard: [undefined, void];
|
||||
applyCodeFromChat: [undefined, void];
|
||||
updateApplyState: [ApplyState, void];
|
||||
startEditMode: [EditModeArgs, void];
|
||||
setEditStatus: [{ status: EditStatus }, void];
|
||||
exitEditMode: [undefined, void];
|
||||
};
|
||||
|
|
|
|||
3301
extensions/intellij/src/main/resources/continue_rc_schema.json
Normal file
3301
extensions/intellij/src/main/resources/continue_rc_schema.json
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -182,6 +182,18 @@
|
|||
"title": "Debug Terminal",
|
||||
"group": "Continue"
|
||||
},
|
||||
{
|
||||
"command": "continue.edit",
|
||||
"category": "Continue",
|
||||
"title": "Edit code with natural language",
|
||||
"group": "Continue"
|
||||
},
|
||||
{
|
||||
"command": "continue.exitEditMode",
|
||||
"category": "Continue",
|
||||
"title": "Exit Edit Mode",
|
||||
"group": "Continue"
|
||||
},
|
||||
{
|
||||
"command": "continue.toggleFullScreen",
|
||||
"category": "Continue",
|
||||
|
|
@ -339,9 +351,20 @@
|
|||
},
|
||||
{
|
||||
"command": "continue.quickEdit",
|
||||
"mac": "cmd+shift+i",
|
||||
"key": "ctrl+shift+i"
|
||||
},
|
||||
{
|
||||
"command": "continue.edit",
|
||||
"mac": "cmd+i",
|
||||
"key": "ctrl+i"
|
||||
},
|
||||
{
|
||||
"command": "continue.exitEditMode",
|
||||
"mac": "escape",
|
||||
"key": "escape",
|
||||
"when": "continue.inEditMode && editorFocus"
|
||||
},
|
||||
{
|
||||
"command": "continue.debugTerminal",
|
||||
"mac": "cmd+shift+r",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { ContextMenuConfig, IDE } from "core";
|
||||
import { CompletionProvider } from "core/autocomplete/completionProvider";
|
||||
import { RangeInFileWithContents } from "core/commands/util";
|
||||
import { ConfigHandler } from "core/config/ConfigHandler";
|
||||
import { getModelByRole } from "core/config/util";
|
||||
import { ContinueServerClient } from "core/continueServer/stubs/client";
|
||||
|
|
@ -27,6 +28,7 @@ import {
|
|||
import { ContinueGUIWebviewViewProvider } from "./ContinueGUIWebviewViewProvider";
|
||||
import { DiffManager } from "./diff/horizontal";
|
||||
import { VerticalDiffManager } from "./diff/vertical/manager";
|
||||
import EditDecorationManager from "./quickEdit/EditDecorationManager";
|
||||
import { QuickEdit, QuickEditShowParams } from "./quickEdit/QuickEditQuickPick";
|
||||
import { Battery } from "./util/battery";
|
||||
import { getFullyQualifiedPath } from "./util/util";
|
||||
|
|
@ -88,20 +90,20 @@ function addCodeToContextFromRange(
|
|||
});
|
||||
}
|
||||
|
||||
async function addHighlightedCodeToContext(
|
||||
webviewProtocol: VsCodeWebviewProtocol | undefined,
|
||||
) {
|
||||
function getCurrentlyHighlightedCode(
|
||||
allowEmpty?: boolean,
|
||||
): RangeInFileWithContents | null {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (editor) {
|
||||
const selection = editor.selection;
|
||||
if (selection.isEmpty) {
|
||||
return;
|
||||
if (selection.isEmpty && !allowEmpty) {
|
||||
return null;
|
||||
}
|
||||
// adjust starting position to include indentation
|
||||
const start = new vscode.Position(selection.start.line, 0);
|
||||
const range = new vscode.Range(start, selection.end);
|
||||
const contents = editor.document.getText(range);
|
||||
const rangeInFileWithContents = {
|
||||
return {
|
||||
filepath: editor.document.uri.fsPath,
|
||||
contents,
|
||||
range: {
|
||||
|
|
@ -115,7 +117,15 @@ async function addHighlightedCodeToContext(
|
|||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function addHighlightedCodeToContext(
|
||||
webviewProtocol: VsCodeWebviewProtocol | undefined,
|
||||
) {
|
||||
const rangeInFileWithContents = getCurrentlyHighlightedCode();
|
||||
if (rangeInFileWithContents) {
|
||||
webviewProtocol?.request("highlightedCode", {
|
||||
rangeInFileWithContents,
|
||||
});
|
||||
|
|
@ -188,6 +198,7 @@ const commandsMap: (
|
|||
battery: Battery,
|
||||
quickEdit: QuickEdit,
|
||||
core: Core,
|
||||
editDecorationManager: EditDecorationManager,
|
||||
) => { [command: string]: (...args: any) => any } = (
|
||||
ide,
|
||||
extensionContext,
|
||||
|
|
@ -199,6 +210,7 @@ const commandsMap: (
|
|||
battery,
|
||||
quickEdit,
|
||||
core,
|
||||
editDecorationManager,
|
||||
) => {
|
||||
/**
|
||||
* Streams an inline edit to the vertical diff manager.
|
||||
|
|
@ -255,6 +267,9 @@ const commandsMap: (
|
|||
|
||||
verticalDiffManager.clearForFilepath(fullPath, true);
|
||||
await diffManager.acceptDiff(fullPath);
|
||||
await sidebar.webviewProtocol.request("setEditStatus", {
|
||||
status: "done",
|
||||
});
|
||||
},
|
||||
"continue.rejectDiff": async (newFilepath?: string | vscode.Uri) => {
|
||||
captureCommandTelemetry("rejectDiff");
|
||||
|
|
@ -269,6 +284,9 @@ const commandsMap: (
|
|||
|
||||
verticalDiffManager.clearForFilepath(fullPath, false);
|
||||
await diffManager.rejectDiff(fullPath);
|
||||
await sidebar.webviewProtocol.request("setEditStatus", {
|
||||
status: "done",
|
||||
});
|
||||
},
|
||||
"continue.acceptVerticalDiffBlock": (filepath?: string, index?: number) => {
|
||||
captureCommandTelemetry("acceptVerticalDiffBlock");
|
||||
|
|
@ -361,8 +379,54 @@ const commandsMap: (
|
|||
await addHighlightedCodeToContext(sidebar.webviewProtocol);
|
||||
}
|
||||
},
|
||||
"continue.edit": async () => {
|
||||
captureCommandTelemetry("edit");
|
||||
const fullScreenTab = getFullScreenTab();
|
||||
if (!fullScreenTab) {
|
||||
// focus sidebar
|
||||
vscode.commands.executeCommand("continue.continueGUIView.focus");
|
||||
} else {
|
||||
// focus fullscreen
|
||||
fullScreenPanel?.reveal();
|
||||
}
|
||||
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
if (!editor) {
|
||||
return;
|
||||
}
|
||||
|
||||
editDecorationManager.setDecoration(
|
||||
editor,
|
||||
new vscode.Range(editor.selection.start, editor.selection.end),
|
||||
);
|
||||
|
||||
const highlightedCode = getCurrentlyHighlightedCode(true)!;
|
||||
await sidebar.webviewProtocol?.request("startEditMode", {
|
||||
highlightedCode,
|
||||
});
|
||||
|
||||
// Un-select the current selection
|
||||
editor.selection = new vscode.Selection(
|
||||
editor.selection.anchor,
|
||||
editor.selection.anchor,
|
||||
);
|
||||
|
||||
setTimeout(() => {
|
||||
sidebar.webviewProtocol?.request("focusContinueInput", undefined);
|
||||
}, 30);
|
||||
},
|
||||
"continue.exitEditMode": async () => {
|
||||
captureCommandTelemetry("exitEditMode");
|
||||
await sidebar.webviewProtocol?.request("exitEditMode", undefined);
|
||||
},
|
||||
"continue.quickEdit": async (args: QuickEditShowParams) => {
|
||||
captureCommandTelemetry("quickEdit");
|
||||
let linesOfCode = undefined;
|
||||
if (args.range) {
|
||||
linesOfCode = args.range.end.line - args.range.start.line;
|
||||
}
|
||||
captureCommandTelemetry("quickEdit", {
|
||||
linesOfCode,
|
||||
});
|
||||
quickEdit.show(args);
|
||||
},
|
||||
"continue.writeCommentsForCode": async () => {
|
||||
|
|
@ -753,6 +817,7 @@ export function registerAllCommands(
|
|||
battery: Battery,
|
||||
quickEdit: QuickEdit,
|
||||
core: Core,
|
||||
editDecorationManager: EditDecorationManager,
|
||||
) {
|
||||
for (const [command, callback] of Object.entries(
|
||||
commandsMap(
|
||||
|
|
@ -766,6 +831,7 @@ export function registerAllCommands(
|
|||
battery,
|
||||
quickEdit,
|
||||
core,
|
||||
editDecorationManager,
|
||||
),
|
||||
)) {
|
||||
context.subscriptions.push(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import { DiffLine } from "core";
|
||||
import { ConfigHandler } from "core/config/ConfigHandler";
|
||||
import { streamDiffLines } from "core/edit/streamDiffLines";
|
||||
import { pruneLinesFromBottom, pruneLinesFromTop } from "core/llm/countTokens";
|
||||
import { getMarkdownLanguageTagForFile } from "core/util";
|
||||
import { DiffLine } from "core";
|
||||
import { streamDiffLines } from "core/edit/streamDiffLines";
|
||||
import * as vscode from "vscode";
|
||||
import EditDecorationManager from "../../quickEdit/EditDecorationManager";
|
||||
import { VsCodeWebviewProtocol } from "../../webviewProtocol";
|
||||
import { VerticalDiffHandler, VerticalDiffHandlerOptions } from "./handler";
|
||||
|
||||
|
|
@ -27,6 +28,7 @@ export class VerticalDiffManager {
|
|||
constructor(
|
||||
private readonly configHandler: ConfigHandler,
|
||||
private readonly webviewProtocol: VsCodeWebviewProtocol,
|
||||
private readonly editDecorationManager: EditDecorationManager,
|
||||
) {
|
||||
this.userChangeListener = undefined;
|
||||
}
|
||||
|
|
@ -240,7 +242,7 @@ export class VerticalDiffManager {
|
|||
|
||||
try {
|
||||
this.logDiffs = await diffHandler.run(diffStream);
|
||||
|
||||
|
||||
// enable a listener for user edits to file while diff is open
|
||||
this.enableDocumentChangeListener();
|
||||
} catch (e) {
|
||||
|
|
@ -411,6 +413,8 @@ export class VerticalDiffManager {
|
|||
true,
|
||||
);
|
||||
|
||||
this.editDecorationManager.clear();
|
||||
|
||||
try {
|
||||
this.logDiffs = await diffHandler.run(
|
||||
streamDiffLines(
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import { ContinueGUIWebviewViewProvider } from "../ContinueGUIWebviewViewProvide
|
|||
import { DiffManager } from "../diff/horizontal";
|
||||
import { VerticalDiffManager } from "../diff/vertical/manager";
|
||||
import { registerAllCodeLensProviders } from "../lang-server/codeLens";
|
||||
import EditDecorationManager from "../quickEdit/EditDecorationManager";
|
||||
import { QuickEdit } from "../quickEdit/QuickEditQuickPick";
|
||||
import { setupRemoteConfigSync } from "../stubs/activation";
|
||||
import {
|
||||
|
|
@ -42,6 +43,7 @@ export class VsCodeExtension {
|
|||
private sidebar: ContinueGUIWebviewViewProvider;
|
||||
private windowId: string;
|
||||
private diffManager: DiffManager;
|
||||
private editDecorationManager: EditDecorationManager;
|
||||
private verticalDiffManager: VerticalDiffManager;
|
||||
webviewProtocolPromise: Promise<VsCodeWebviewProtocol>;
|
||||
private core: Core;
|
||||
|
|
@ -54,6 +56,8 @@ export class VsCodeExtension {
|
|||
this.workOsAuthProvider.refreshSessions();
|
||||
context.subscriptions.push(this.workOsAuthProvider);
|
||||
|
||||
this.editDecorationManager = new EditDecorationManager(context);
|
||||
|
||||
let resolveWebviewProtocol: any = undefined;
|
||||
this.webviewProtocolPromise = new Promise<VsCodeWebviewProtocol>(
|
||||
(resolve) => {
|
||||
|
|
@ -110,6 +114,7 @@ export class VsCodeExtension {
|
|||
verticalDiffManagerPromise,
|
||||
configHandlerPromise,
|
||||
this.workOsAuthProvider,
|
||||
this.editDecorationManager,
|
||||
);
|
||||
|
||||
this.core = new Core(inProcessMessenger, this.ide, async (log: string) => {
|
||||
|
|
@ -128,6 +133,7 @@ export class VsCodeExtension {
|
|||
this.verticalDiffManager = new VerticalDiffManager(
|
||||
this.configHandler,
|
||||
this.sidebar.webviewProtocol,
|
||||
this.editDecorationManager,
|
||||
);
|
||||
resolveVerticalDiffManager?.(this.verticalDiffManager);
|
||||
this.tabAutocompleteModel = new TabAutocompleteModel(this.configHandler);
|
||||
|
|
@ -221,6 +227,7 @@ export class VsCodeExtension {
|
|||
this.battery,
|
||||
quickEdit,
|
||||
this.core,
|
||||
this.editDecorationManager,
|
||||
);
|
||||
|
||||
// Disabled due to performance issues
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { ConfigHandler } from "core/config/ConfigHandler";
|
||||
import { getModelByRole } from "core/config/util";
|
||||
import { applyCodeBlock } from "core/edit/lazy/applyCodeBlock";
|
||||
import { stripImages } from "core/llm/images";
|
||||
import {
|
||||
FromCoreProtocol,
|
||||
FromWebviewProtocol,
|
||||
|
|
@ -20,6 +21,7 @@ import * as fs from "node:fs";
|
|||
import * as path from "node:path";
|
||||
import * as vscode from "vscode";
|
||||
import { VerticalDiffManager } from "../diff/vertical/manager";
|
||||
import EditDecorationManager from "../quickEdit/EditDecorationManager";
|
||||
import {
|
||||
getControlPlaneSessionInfo,
|
||||
WorkOsAuthProvider,
|
||||
|
|
@ -79,6 +81,7 @@ export class VsCodeMessenger {
|
|||
private readonly verticalDiffManagerPromise: Promise<VerticalDiffManager>,
|
||||
private readonly configHandlerPromise: Promise<ConfigHandler>,
|
||||
private readonly workOsAuthProvider: WorkOsAuthProvider,
|
||||
private readonly editDecorationManager: EditDecorationManager,
|
||||
) {
|
||||
/** WEBVIEW ONLY LISTENERS **/
|
||||
this.onWebview("showFile", (msg) => {
|
||||
|
|
@ -160,7 +163,9 @@ export class VsCodeMessenger {
|
|||
|
||||
// If document is empty, insert at 0,0 and finish
|
||||
if (!editor.document.getText().trim()) {
|
||||
editor.edit(builder => builder.insert(new vscode.Position(0, 0), data.text));
|
||||
editor.edit((builder) =>
|
||||
builder.insert(new vscode.Position(0, 0), data.text),
|
||||
);
|
||||
await webviewProtocol.request("updateApplyState", {
|
||||
streamId: data.streamId,
|
||||
status: "done",
|
||||
|
|
@ -175,7 +180,9 @@ export class VsCodeMessenger {
|
|||
let llm = getModelByRole(config, "applyCodeBlock");
|
||||
|
||||
if (!llm) {
|
||||
llm = config.models.find((model) => model.title === data.curSelectedModelTitle);
|
||||
llm = config.models.find(
|
||||
(model) => model.title === data.curSelectedModelTitle,
|
||||
);
|
||||
|
||||
if (!llm) {
|
||||
vscode.window.showErrorMessage(
|
||||
|
|
@ -263,6 +270,57 @@ export class VsCodeMessenger {
|
|||
);
|
||||
});
|
||||
});
|
||||
this.onWebview("edit/sendPrompt", async (msg) => {
|
||||
const prompt = msg.data.prompt;
|
||||
const { start, end } = msg.data.range.range;
|
||||
const verticalDiffManager = await verticalDiffManagerPromise;
|
||||
const modelTitle = await this.webviewProtocol.request(
|
||||
"getDefaultModelTitle",
|
||||
undefined,
|
||||
);
|
||||
await verticalDiffManager.streamEdit(
|
||||
stripImages(prompt),
|
||||
modelTitle,
|
||||
"edit",
|
||||
undefined,
|
||||
undefined,
|
||||
new vscode.Range(
|
||||
new vscode.Position(start.line, start.character),
|
||||
new vscode.Position(end.line, end.character),
|
||||
),
|
||||
);
|
||||
|
||||
this.webviewProtocol.request("setEditStatus", {
|
||||
status: "accepting",
|
||||
});
|
||||
});
|
||||
this.onWebview("edit/acceptReject", async (msg) => {
|
||||
const { onlyFirst, accept, filepath } = msg.data;
|
||||
if (accept && onlyFirst) {
|
||||
// Accept first
|
||||
vscode.commands.executeCommand(
|
||||
"continue.acceptVerticalDiffBlock",
|
||||
filepath,
|
||||
0,
|
||||
);
|
||||
} else if (accept) {
|
||||
vscode.commands.executeCommand("continue.acceptDiff", filepath);
|
||||
// Accept all
|
||||
} else if (onlyFirst) {
|
||||
// Reject first
|
||||
vscode.commands.executeCommand(
|
||||
"continue.rejectVerticalDiffBlock",
|
||||
filepath,
|
||||
0,
|
||||
);
|
||||
} else {
|
||||
// Reject all
|
||||
vscode.commands.executeCommand("continue.rejectDiff", filepath);
|
||||
}
|
||||
});
|
||||
this.onWebview("edit/escape", async (msg) => {
|
||||
this.editDecorationManager.clear();
|
||||
});
|
||||
|
||||
/** PASS THROUGH FROM WEBVIEW TO CORE AND BACK **/
|
||||
WEBVIEW_TO_CORE_PASS_THROUGH.forEach((messageType) => {
|
||||
|
|
|
|||
44
extensions/vscode/src/quickEdit/EditDecorationManager.ts
Normal file
44
extensions/vscode/src/quickEdit/EditDecorationManager.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import vscode from "vscode";
|
||||
class EditDecorationManager {
|
||||
private _lastEditor: vscode.TextEditor | undefined;
|
||||
private decorationType: vscode.TextEditorDecorationType;
|
||||
|
||||
constructor(context: vscode.ExtensionContext) {
|
||||
this.decorationType = vscode.window.createTextEditorDecorationType({
|
||||
backgroundColor: "rgba(255, 255, 0, 0.1)",
|
||||
borderWidth: "0 0 0 1px",
|
||||
borderColor: "rgba(255, 255, 0)",
|
||||
borderStyle: "solid",
|
||||
isWholeLine: true,
|
||||
cursor: "pointer",
|
||||
// gutterIconPath: context.asAbsolutePath("media/gutterIcon.png"),
|
||||
gutterIconSize: "contain",
|
||||
});
|
||||
}
|
||||
|
||||
private updateInEditMode(inEditMode: boolean) {
|
||||
vscode.commands.executeCommand(
|
||||
"setContext",
|
||||
"continue.inEditMode",
|
||||
inEditMode,
|
||||
);
|
||||
}
|
||||
|
||||
setDecoration(editor: vscode.TextEditor, range: vscode.Range) {
|
||||
if (this._lastEditor) {
|
||||
this._lastEditor.setDecorations(this.decorationType, []);
|
||||
}
|
||||
editor.setDecorations(this.decorationType, [range]);
|
||||
this._lastEditor = editor;
|
||||
this.updateInEditMode(true);
|
||||
}
|
||||
|
||||
clear() {
|
||||
if (this._lastEditor) {
|
||||
this._lastEditor.setDecorations(this.decorationType, []);
|
||||
this._lastEditor = undefined;
|
||||
this.updateInEditMode(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
export default EditDecorationManager;
|
||||
|
|
@ -7,8 +7,10 @@ import useSetup from "./hooks/useSetup";
|
|||
import useSubmenuContextProviders from "./hooks/useSubmenuContextProviders";
|
||||
import { useVscTheme } from "./hooks/useVscTheme";
|
||||
import { AddNewModel, ConfigureProvider } from "./pages/AddNewModel";
|
||||
import ConfigErrorPage from "./pages/config-error";
|
||||
import Edit from "./pages/edit";
|
||||
import ErrorPage from "./pages/error";
|
||||
import GUI from "./pages/gui";
|
||||
import Chat from "./pages/gui";
|
||||
import History from "./pages/history";
|
||||
import MigrationPage from "./pages/migration";
|
||||
import MonacoPage from "./pages/monaco";
|
||||
|
|
@ -16,7 +18,6 @@ import MorePage from "./pages/More";
|
|||
import SettingsPage from "./pages/settings";
|
||||
import Stats from "./pages/stats";
|
||||
import { ROUTES } from "./util/navigation";
|
||||
import ConfigErrorPage from "./pages/config-error";
|
||||
|
||||
const router = createMemoryRouter([
|
||||
{
|
||||
|
|
@ -26,11 +27,15 @@ const router = createMemoryRouter([
|
|||
children: [
|
||||
{
|
||||
path: "/index.html",
|
||||
element: <GUI />,
|
||||
element: <Chat />,
|
||||
},
|
||||
{
|
||||
path: "/",
|
||||
element: <GUI />,
|
||||
element: <Chat />,
|
||||
},
|
||||
{
|
||||
path: "/edit",
|
||||
element: <Edit />,
|
||||
},
|
||||
{
|
||||
path: "/history",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@ import { IdeMessengerContext } from "../context/IdeMessenger";
|
|||
import { LastSessionProvider } from "../context/LastSessionContext";
|
||||
import { useWebviewListener } from "../hooks/useWebviewListener";
|
||||
import { useConfigError } from "../redux/hooks";
|
||||
import {
|
||||
setEditDone,
|
||||
setEditStatus,
|
||||
startEditMode,
|
||||
} from "../redux/slices/editModeState";
|
||||
import { setShowDialog, updateApplyState } from "../redux/slices/uiStateSlice";
|
||||
import { RootState } from "../redux/store";
|
||||
import { getFontSize, isMetaEquivalentKeyPressed } from "../util";
|
||||
|
|
@ -174,6 +179,24 @@ const Layout = () => {
|
|||
[],
|
||||
);
|
||||
|
||||
useWebviewListener(
|
||||
"startEditMode",
|
||||
async (args) => {
|
||||
dispatch(startEditMode(args));
|
||||
navigate("/edit");
|
||||
},
|
||||
[navigate],
|
||||
);
|
||||
|
||||
useWebviewListener("setEditStatus", async ({ status }) => {
|
||||
dispatch(setEditStatus(status));
|
||||
});
|
||||
|
||||
useWebviewListener("exitEditMode", async () => {
|
||||
dispatch(setEditDone());
|
||||
navigate("/");
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
isNewUserOnboarding() &&
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { JSONContent } from "@tiptap/react";
|
||||
import { Editor, JSONContent } from "@tiptap/react";
|
||||
import { ContextItemWithId, InputModifiers } from "core";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import styled, { keyframes } from "styled-components";
|
||||
import { defaultBorderRadius, vscBackground } from "..";
|
||||
|
|
@ -9,12 +10,15 @@ import { newSession, setMessageAtIndex } from "../../redux/slices/stateSlice";
|
|||
import { RootState } from "../../redux/store";
|
||||
import ContextItemsPeek from "./ContextItemsPeek";
|
||||
import TipTapEditor from "./TipTapEditor";
|
||||
import { useState, useRef, useEffect } from "react";
|
||||
|
||||
interface ContinueInputBoxProps {
|
||||
isLastUserInput: boolean;
|
||||
isMainInput?: boolean;
|
||||
onEnter: (editorState: JSONContent, modifiers: InputModifiers) => void;
|
||||
onEnter: (
|
||||
editorState: JSONContent,
|
||||
modifiers: InputModifiers,
|
||||
editor: Editor,
|
||||
) => void;
|
||||
editorState?: JSONContent;
|
||||
contextItems?: ContextItemWithId[];
|
||||
hidden?: boolean;
|
||||
|
|
@ -105,8 +109,8 @@ function ContinueInputBox(props: ContinueInputBoxProps) {
|
|||
}, [isGatheringContextStore]);
|
||||
|
||||
return (
|
||||
<div className={`mt-3 mb-1 ${props.hidden ? "hidden" : ""}`}>
|
||||
<div className={`flex px-2 relative`}>
|
||||
<div className={`mb-1 mt-3 ${props.hidden ? "hidden" : ""}`}>
|
||||
<div className={`relative flex px-2`}>
|
||||
<GradientBorder
|
||||
loading={active && props.isLastUserInput ? 1 : 0}
|
||||
borderColor={
|
||||
|
|
@ -116,10 +120,16 @@ function ContinueInputBox(props: ContinueInputBoxProps) {
|
|||
>
|
||||
<TipTapEditor
|
||||
editorState={props.editorState}
|
||||
onEnter={props.onEnter}
|
||||
onEnter={(...args) => {
|
||||
props.onEnter(...args);
|
||||
if (props.isMainInput) {
|
||||
args[2].commands.clearContent(true);
|
||||
}
|
||||
}}
|
||||
isMainInput={props.isMainInput ?? false}
|
||||
availableContextProviders={availableContextProviders ?? []}
|
||||
availableSlashCommands={availableSlashCommands}
|
||||
historyKey="chat"
|
||||
/>
|
||||
</GradientBorder>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
import {
|
||||
AtSymbolIcon,
|
||||
PhotoIcon,
|
||||
SlashIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { AtSymbolIcon, PhotoIcon } from "@heroicons/react/24/outline";
|
||||
import { InputModifiers } from "core";
|
||||
import { modelSupportsImages } from "core/llm/autodetect";
|
||||
import { useRef } from "react";
|
||||
|
|
@ -11,8 +7,6 @@ import styled from "styled-components";
|
|||
import {
|
||||
defaultBorderRadius,
|
||||
lightGray,
|
||||
vscBadgeBackground,
|
||||
vscBadgeForeground,
|
||||
vscForeground,
|
||||
vscInputBackground,
|
||||
} from "..";
|
||||
|
|
@ -24,8 +18,8 @@ import {
|
|||
getMetaKeyLabel,
|
||||
isMetaEquivalentKeyPressed,
|
||||
} from "../../util";
|
||||
import ModelSelect from "../modelSelection/ModelSelect";
|
||||
import { ToolTip } from "../gui/Tooltip";
|
||||
import ModelSelect from "../modelSelection/ModelSelect";
|
||||
|
||||
const StyledDiv = styled.div<{ isHidden: boolean }>`
|
||||
padding: 4px 0;
|
||||
|
|
@ -69,6 +63,14 @@ const EnterButton = styled.button`
|
|||
}
|
||||
`;
|
||||
|
||||
export interface ToolbarOptions {
|
||||
hideUseCodebase?: boolean;
|
||||
hideImageUpload?: boolean;
|
||||
hideAddContext?: boolean;
|
||||
enterText?: string;
|
||||
hideSelectModel?: boolean;
|
||||
}
|
||||
|
||||
interface InputToolbarProps {
|
||||
onEnter?: (modifiers: InputModifiers) => void;
|
||||
onAddContextItem?: () => void;
|
||||
|
|
@ -77,6 +79,7 @@ interface InputToolbarProps {
|
|||
onImageFileSelected?: (file: File) => void;
|
||||
hidden?: boolean;
|
||||
activeKey: string | null;
|
||||
toolbarOptions?: ToolbarOptions;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
|
|
@ -105,69 +108,73 @@ function InputToolbar(props: InputToolbarProps) {
|
|||
<div className="flex items-center justify-start gap-2 whitespace-nowrap">
|
||||
<ModelSelect />
|
||||
<div className="xs:flex -mb-1 hidden items-center gap-1 text-gray-400 transition-colors duration-200">
|
||||
{supportsImages && (
|
||||
<>
|
||||
<input
|
||||
type="file"
|
||||
ref={fileInputRef}
|
||||
style={{ display: "none" }}
|
||||
accept=".jpg,.jpeg,.png,.gif,.svg,.webp"
|
||||
onChange={(e) => {
|
||||
for (const file of e.target.files) {
|
||||
props.onImageFileSelected(file);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<HoverItem>
|
||||
<PhotoIcon
|
||||
className="h-4 w-4"
|
||||
onClick={(e) => {
|
||||
fileInputRef.current?.click();
|
||||
{props.toolbarOptions?.hideImageUpload ||
|
||||
(supportsImages && (
|
||||
<>
|
||||
<input
|
||||
type="file"
|
||||
ref={fileInputRef}
|
||||
style={{ display: "none" }}
|
||||
accept=".jpg,.jpeg,.png,.gif,.svg,.webp"
|
||||
onChange={(e) => {
|
||||
for (const file of e.target.files) {
|
||||
props.onImageFileSelected(file);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</HoverItem>
|
||||
</>
|
||||
)}
|
||||
<HoverItem>
|
||||
<PhotoIcon
|
||||
className="h-4 w-4"
|
||||
onClick={(e) => {
|
||||
fileInputRef.current?.click();
|
||||
}}
|
||||
/>
|
||||
</HoverItem>
|
||||
</>
|
||||
))}
|
||||
{props.toolbarOptions?.hideAddContext || (
|
||||
<HoverItem onClick={props.onAddContextItem}>
|
||||
<AtSymbolIcon
|
||||
data-tooltip-id="add-context-item-tooltip"
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
|
||||
<HoverItem onClick={props.onAddContextItem}>
|
||||
<AtSymbolIcon
|
||||
data-tooltip-id="add-context-item-tooltip"
|
||||
className="h-4 w-4"
|
||||
/>
|
||||
|
||||
<ToolTip id="add-context-item-tooltip" place="top-start">
|
||||
Add context (files, docs, urls, etc.)
|
||||
</ToolTip>
|
||||
</HoverItem>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 whitespace-nowrap text-gray-400">
|
||||
<div className="hidden transition-colors duration-200 hover:underline sm:flex">
|
||||
{props.activeKey === "Alt" ? (
|
||||
<HoverItem className="underline">
|
||||
{`${getAltKeyLabel()}⏎
|
||||
${useActiveFile ? "No active file" : "Active file"}`}
|
||||
</HoverItem>
|
||||
) : (
|
||||
<HoverItem
|
||||
className={props.activeKey === "Meta" && "underline"}
|
||||
onClick={(e) =>
|
||||
props.onEnter({
|
||||
useCodebase: true,
|
||||
noContext: !useActiveFile,
|
||||
})
|
||||
}
|
||||
>
|
||||
<span data-tooltip-id="add-codebase-context-tooltip">
|
||||
{getMetaKeyLabel()}⏎ @codebase
|
||||
</span>
|
||||
<ToolTip id="add-codebase-context-tooltip" place="top-end">
|
||||
Submit with the codebase as context ({getMetaKeyLabel()}⏎)
|
||||
<ToolTip id="add-context-item-tooltip" place="top-start">
|
||||
Add context (files, docs, urls, etc.)
|
||||
</ToolTip>
|
||||
</HoverItem>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 whitespace-nowrap text-gray-400">
|
||||
{props.toolbarOptions?.hideUseCodebase || (
|
||||
<div className="hidden transition-colors duration-200 hover:underline sm:flex">
|
||||
{props.activeKey === "Alt" ? (
|
||||
<HoverItem className="underline">
|
||||
{`${getAltKeyLabel()}⏎
|
||||
${useActiveFile ? "No active file" : "Active file"}`}
|
||||
</HoverItem>
|
||||
) : (
|
||||
<HoverItem
|
||||
className={props.activeKey === "Meta" && "underline"}
|
||||
onClick={(e) =>
|
||||
props.onEnter({
|
||||
useCodebase: true,
|
||||
noContext: !useActiveFile,
|
||||
})
|
||||
}
|
||||
>
|
||||
<span data-tooltip-id="add-codebase-context-tooltip">
|
||||
{getMetaKeyLabel()}⏎ @codebase
|
||||
</span>
|
||||
<ToolTip id="add-codebase-context-tooltip" place="top-end">
|
||||
Submit with the codebase as context ({getMetaKeyLabel()}⏎)
|
||||
</ToolTip>
|
||||
</HoverItem>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<EnterButton
|
||||
onClick={(e) => {
|
||||
|
|
@ -178,7 +185,9 @@ function InputToolbar(props: InputToolbarProps) {
|
|||
}}
|
||||
disabled={props.disabled}
|
||||
>
|
||||
<span className="hidden md:inline">⏎ Enter</span>
|
||||
<span className="hidden md:inline">
|
||||
⏎ {props.toolbarOptions?.enterText ?? "Enter"}
|
||||
</span>
|
||||
<span className="md:hidden">⏎</span>
|
||||
</EnterButton>
|
||||
</div>
|
||||
|
|
|
|||
23
gui/src/components/mainInput/NewSessionButton.tsx
Normal file
23
gui/src/components/mainInput/NewSessionButton.tsx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import styled from "styled-components";
|
||||
import { defaultBorderRadius, lightGray, vscForeground } from "..";
|
||||
import { getFontSize } from "../../util";
|
||||
|
||||
export const NewSessionButton = styled.div`
|
||||
width: fit-content;
|
||||
margin-right: auto;
|
||||
margin-left: 6px;
|
||||
margin-top: 2px;
|
||||
margin-bottom: 8px;
|
||||
font-size: ${getFontSize() - 2}px;
|
||||
|
||||
border-radius: ${defaultBorderRadius};
|
||||
padding: 2px 6px;
|
||||
color: ${lightGray};
|
||||
|
||||
&:hover {
|
||||
background-color: ${lightGray}33;
|
||||
color: ${vscForeground};
|
||||
}
|
||||
|
||||
cursor: pointer;
|
||||
`;
|
||||
|
|
@ -55,7 +55,7 @@ import {
|
|||
import { handleMetaKeyPressJetBrains } from "../../util/handleMetaKeyPressJetBrains";
|
||||
import { CodeBlockExtension } from "./CodeBlockExtension";
|
||||
import { SlashCommand } from "./CommandsExtension";
|
||||
import InputToolbar from "./InputToolbar";
|
||||
import InputToolbar, { ToolbarOptions } from "./InputToolbar";
|
||||
import { Mention } from "./MentionExtension";
|
||||
import "./TipTapEditor.css";
|
||||
import {
|
||||
|
|
@ -64,18 +64,18 @@ import {
|
|||
} from "./getSuggestion";
|
||||
import { ComboBoxItem } from "./types";
|
||||
|
||||
const InputBoxDiv = styled.div`
|
||||
const InputBoxDiv = styled.div<{ border?: string }>`
|
||||
resize: none;
|
||||
padding: 8px 12px;
|
||||
padding-bottom: 4px;
|
||||
font-family: inherit;
|
||||
border-radius: ${defaultBorderRadius};
|
||||
margin: 0;
|
||||
height: auto;
|
||||
width: calc(100% - 24px);
|
||||
width: 100%;
|
||||
background-color: ${vscInputBackground};
|
||||
color: ${vscForeground};
|
||||
border: 0.5px solid ${vscInputBorder};
|
||||
border: ${(props) =>
|
||||
props.border ? props.border : `0.5px solid ${vscInputBorder}`};
|
||||
outline: none;
|
||||
font-size: ${getFontSize()}px;
|
||||
&:focus {
|
||||
|
|
@ -92,6 +92,11 @@ const InputBoxDiv = styled.div`
|
|||
flex-direction: column;
|
||||
`;
|
||||
|
||||
const PaddingDiv = styled.div`
|
||||
padding: 8px 12px;
|
||||
padding-bottom: 4px;
|
||||
`;
|
||||
|
||||
const HoverDiv = styled.div`
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
|
|
@ -141,8 +146,17 @@ interface TipTapEditorProps {
|
|||
availableContextProviders: ContextProviderDescription[];
|
||||
availableSlashCommands: ComboBoxItem[];
|
||||
isMainInput: boolean;
|
||||
onEnter: (editorState: JSONContent, modifiers: InputModifiers) => void;
|
||||
onEnter: (
|
||||
editorState: JSONContent,
|
||||
modifiers: InputModifiers,
|
||||
editor: Editor,
|
||||
) => void;
|
||||
editorState?: JSONContent;
|
||||
toolbarOptions?: ToolbarOptions;
|
||||
border?: string;
|
||||
placeholder?: string;
|
||||
header?: React.ReactNode;
|
||||
historyKey: string;
|
||||
}
|
||||
|
||||
function TipTapEditor(props: TipTapEditorProps) {
|
||||
|
|
@ -285,7 +299,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
(store: RootState) => store.state.mainEditorContent,
|
||||
);
|
||||
|
||||
const { prevRef, nextRef, addRef } = useInputHistory();
|
||||
const { prevRef, nextRef, addRef } = useInputHistory(props.historyKey);
|
||||
|
||||
function getPlaceholder() {
|
||||
if (!hasDefaultModel) {
|
||||
|
|
@ -337,7 +351,11 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
},
|
||||
}),
|
||||
Placeholder.configure({
|
||||
placeholder: getPlaceholder,
|
||||
placeholder:
|
||||
props.placeholder ??
|
||||
(historyLengthRef.current === 0
|
||||
? "Ask anything, '/' for slash commands, '@' to add context"
|
||||
: "Ask a follow-up"),
|
||||
}),
|
||||
Paragraph.extend({
|
||||
addKeyboardShortcuts() {
|
||||
|
|
@ -429,37 +447,41 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
},
|
||||
}),
|
||||
Text,
|
||||
Mention.configure({
|
||||
HTMLAttributes: {
|
||||
class: "mention",
|
||||
},
|
||||
suggestion: getContextProviderDropdownOptions(
|
||||
availableContextProvidersRef,
|
||||
getSubmenuContextItemsRef,
|
||||
enterSubmenu,
|
||||
onClose,
|
||||
onOpen,
|
||||
inSubmenuRef,
|
||||
ideMessenger,
|
||||
),
|
||||
renderHTML: (props) => {
|
||||
return `@${props.node.attrs.label || props.node.attrs.id}`;
|
||||
},
|
||||
}),
|
||||
SlashCommand.configure({
|
||||
HTMLAttributes: {
|
||||
class: "mention",
|
||||
},
|
||||
suggestion: getSlashCommandDropdownOptions(
|
||||
availableSlashCommandsRef,
|
||||
onClose,
|
||||
onOpen,
|
||||
ideMessenger,
|
||||
),
|
||||
renderText: (props) => {
|
||||
return props.node.attrs.label;
|
||||
},
|
||||
}),
|
||||
props.availableContextProviders.length
|
||||
? Mention.configure({
|
||||
HTMLAttributes: {
|
||||
class: "mention",
|
||||
},
|
||||
suggestion: getContextProviderDropdownOptions(
|
||||
availableContextProvidersRef,
|
||||
getSubmenuContextItemsRef,
|
||||
enterSubmenu,
|
||||
onClose,
|
||||
onOpen,
|
||||
inSubmenuRef,
|
||||
ideMessenger,
|
||||
),
|
||||
renderHTML: (props) => {
|
||||
return `@${props.node.attrs.label || props.node.attrs.id}`;
|
||||
},
|
||||
})
|
||||
: undefined,
|
||||
props.availableSlashCommands.length
|
||||
? SlashCommand.configure({
|
||||
HTMLAttributes: {
|
||||
class: "mention",
|
||||
},
|
||||
suggestion: getSlashCommandDropdownOptions(
|
||||
availableSlashCommandsRef,
|
||||
onClose,
|
||||
onOpen,
|
||||
ideMessenger,
|
||||
),
|
||||
renderText: (props) => {
|
||||
return props.node.attrs.label;
|
||||
},
|
||||
})
|
||||
: undefined,
|
||||
CodeBlockExtension,
|
||||
],
|
||||
editorProps: {
|
||||
|
|
@ -639,12 +661,11 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
return;
|
||||
}
|
||||
|
||||
props.onEnter(json, modifiers);
|
||||
props.onEnter(json, modifiers, editor);
|
||||
|
||||
if (props.isMainInput) {
|
||||
const content = editor.state.toJSON().doc;
|
||||
addRef.current(content);
|
||||
editor.commands.clearContent(true);
|
||||
}
|
||||
},
|
||||
[props.onEnter, editor, props.isMainInput],
|
||||
|
|
@ -859,6 +880,7 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
|
||||
return (
|
||||
<InputBoxDiv
|
||||
border={props.border}
|
||||
onKeyDown={handleKeyDown}
|
||||
onKeyUp={handleKeyUp}
|
||||
className="cursor-text"
|
||||
|
|
@ -903,31 +925,36 @@ function TipTapEditor(props: TipTapEditorProps) {
|
|||
event.preventDefault();
|
||||
}}
|
||||
>
|
||||
<EditorContent
|
||||
spellCheck={false}
|
||||
editor={editor}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
}}
|
||||
/>
|
||||
<InputToolbar
|
||||
activeKey={activeKey}
|
||||
hidden={shouldHideToolbar && !props.isMainInput}
|
||||
onAddContextItem={() => insertCharacterWithWhitespace("@")}
|
||||
onAddSlashCommand={() => insertCharacterWithWhitespace("/")}
|
||||
onEnter={onEnterRef.current}
|
||||
onImageFileSelected={(file) => {
|
||||
handleImageFile(file).then(([img, dataUrl]) => {
|
||||
const { schema } = editor.state;
|
||||
const node = schema.nodes.image.create({ src: dataUrl });
|
||||
editor.commands.command(({ tr }) => {
|
||||
tr.insert(0, node);
|
||||
return true;
|
||||
<div>{props.header}</div>
|
||||
|
||||
<PaddingDiv>
|
||||
<EditorContent
|
||||
spellCheck={false}
|
||||
editor={editor}
|
||||
onClick={(event) => {
|
||||
event.stopPropagation();
|
||||
}}
|
||||
/>
|
||||
<InputToolbar
|
||||
toolbarOptions={props.toolbarOptions}
|
||||
activeKey={activeKey}
|
||||
hidden={shouldHideToolbar && !props.isMainInput}
|
||||
onAddContextItem={() => insertCharacterWithWhitespace("@")}
|
||||
onAddSlashCommand={() => insertCharacterWithWhitespace("/")}
|
||||
onEnter={onEnterRef.current}
|
||||
onImageFileSelected={(file) => {
|
||||
handleImageFile(file).then(([img, dataUrl]) => {
|
||||
const { schema } = editor.state;
|
||||
const node = schema.nodes.image.create({ src: dataUrl });
|
||||
editor.commands.command(({ tr }) => {
|
||||
tr.insert(0, node);
|
||||
return true;
|
||||
});
|
||||
});
|
||||
});
|
||||
}}
|
||||
disabled={active}
|
||||
/>
|
||||
}}
|
||||
disabled={active}
|
||||
/>
|
||||
</PaddingDiv>
|
||||
|
||||
{showDragOverMsg &&
|
||||
modelSupportsImages(
|
||||
|
|
|
|||
|
|
@ -10,9 +10,10 @@ const emptyJsonContent = () => ({
|
|||
|
||||
const MAX_HISTORY_LENGTH = 100;
|
||||
|
||||
export function useInputHistory() {
|
||||
export function useInputHistory(historyKey: string) {
|
||||
const [inputHistory, setInputHistory] = useState<JSONContent[]>(
|
||||
getLocalStorage("inputHistory")?.slice(-MAX_HISTORY_LENGTH) ?? [],
|
||||
getLocalStorage(`inputHistory_${historyKey}`)?.slice(-MAX_HISTORY_LENGTH) ??
|
||||
[],
|
||||
);
|
||||
const [pendingInput, setPendingInput] =
|
||||
useState<JSONContent>(emptyJsonContent());
|
||||
|
|
@ -58,7 +59,7 @@ export function useInputHistory() {
|
|||
return [...prev, inputValue].slice(-MAX_HISTORY_LENGTH);
|
||||
});
|
||||
setLocalStorage(
|
||||
"inputHistory",
|
||||
`inputHistory_${historyKey}`,
|
||||
[...inputHistory, inputValue].slice(-MAX_HISTORY_LENGTH),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
250
gui/src/pages/edit.tsx
Normal file
250
gui/src/pages/edit.tsx
Normal file
|
|
@ -0,0 +1,250 @@
|
|||
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
|
||||
import { Editor, JSONContent } from "@tiptap/core";
|
||||
import { InputModifiers } from "core";
|
||||
import { getBasename } from "core/util";
|
||||
import { usePostHog } from "posthog-js/react";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import styled from "styled-components";
|
||||
import { defaultBorderRadius, lightGray, vscForeground } from "../components";
|
||||
import FileIcon from "../components/FileIcon";
|
||||
import { NewSessionButton } from "../components/mainInput/NewSessionButton";
|
||||
import resolveEditorContent from "../components/mainInput/resolveInput";
|
||||
import TipTapEditor from "../components/mainInput/TipTapEditor";
|
||||
import { IdeMessengerContext } from "../context/IdeMessenger";
|
||||
import { setEditDone, submitEdit } from "../redux/slices/editModeState";
|
||||
import { RootState } from "../redux/store";
|
||||
import { getMetaKeyLabel } from "../util";
|
||||
|
||||
const TopDiv = styled.div`
|
||||
overflow-y: auto;
|
||||
height: 100%;
|
||||
scrollbar-width: none;
|
||||
&::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
`;
|
||||
|
||||
const AcceptRejectButton = styled.div<{
|
||||
backgroundColor: string;
|
||||
disabled: boolean;
|
||||
}>`
|
||||
border: none;
|
||||
background-color: ${(props) => props.backgroundColor};
|
||||
border-radius: ${defaultBorderRadius};
|
||||
padding: 8px 16px;
|
||||
color: ${vscForeground};
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
margin: 0 8px;
|
||||
transition: filter 0.2s ease;
|
||||
|
||||
opacity: ${(props) => (props.disabled ? 0.5 : 1)};
|
||||
cursor: ${(props) => (props.disabled ? "default" : "pointer")};
|
||||
|
||||
&:hover {
|
||||
filter: ${(props) => (props.disabled ? "none" : "brightness(1.2)")};
|
||||
}
|
||||
`;
|
||||
|
||||
const EditHistoryDiv = styled.div`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
padding: 8px 16px;
|
||||
|
||||
cursor: pointer;
|
||||
|
||||
border: 1px solid ${lightGray}55;
|
||||
border-radius: ${defaultBorderRadius};
|
||||
|
||||
&:hover {
|
||||
background-color: ${lightGray}22;
|
||||
}
|
||||
`;
|
||||
|
||||
const EDIT_ALLOWS_CONTEXT_PROVIDERS = ["file", "code"];
|
||||
|
||||
function Edit() {
|
||||
const posthog = usePostHog();
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const editModeState = useSelector((state: RootState) => state.editModeState);
|
||||
const availableContextProviders = useSelector(
|
||||
(store: RootState) => store.state.config.contextProviders,
|
||||
);
|
||||
useEffect(() => {}, []);
|
||||
|
||||
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);
|
||||
navigate("/");
|
||||
}
|
||||
}, [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 (
|
||||
<>
|
||||
<TopDiv>
|
||||
<div className="m-auto max-w-3xl">
|
||||
{/* Edit session history */}
|
||||
{/* {editModeState.previousInputs.length > 0 && (
|
||||
<div className="mt-3 px-2">
|
||||
{editModeState.previousInputs.map((input, index) => (
|
||||
<div key={index} className="flex items-center gap-2">
|
||||
<EditHistoryDiv>
|
||||
<div className="text-gray-400">{stripImages(input)}</div>
|
||||
<EyeIcon className="ml-auto h-4 w-4" color={lightGray} />
|
||||
</EditHistoryDiv>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)} */}
|
||||
|
||||
<div className="relative mb-1 mt-3 flex px-2">
|
||||
<TipTapEditor
|
||||
header={
|
||||
<div
|
||||
className="select-none p-1"
|
||||
style={{
|
||||
backgroundColor: "#fff2",
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="flex cursor-pointer"
|
||||
onClick={() => {
|
||||
ideMessenger.ide.showLines(
|
||||
editModeState.highlightedCode.filepath,
|
||||
editModeState.highlightedCode.range.start.line,
|
||||
editModeState.highlightedCode.range.end.line,
|
||||
);
|
||||
setShowCode(!showCode);
|
||||
}}
|
||||
>
|
||||
<FileIcon
|
||||
filename={editModeState.highlightedCode.filepath}
|
||||
height={"18px"}
|
||||
width={"18px"}
|
||||
></FileIcon>
|
||||
{getBasename(editModeState.highlightedCode.filepath)} (
|
||||
{editModeState.highlightedCode.range.start.line}-
|
||||
{editModeState.highlightedCode.range.end.line})
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
toolbarOptions={{
|
||||
hideAddContext: true,
|
||||
hideImageUpload: true,
|
||||
hideUseCodebase: true,
|
||||
hideSelectModel: false,
|
||||
enterText: ["streaming", "accepting"].includes(
|
||||
editModeState.editStatus,
|
||||
)
|
||||
? "Retry"
|
||||
: "Edit",
|
||||
}}
|
||||
placeholder={
|
||||
["streaming", "accepting"].includes(editModeState.editStatus)
|
||||
? "Enter instructions for edit"
|
||||
: "Enter follow-up instructions"
|
||||
}
|
||||
border={`1px solid #aa0`}
|
||||
availableContextProviders={availableContextProviders.filter(
|
||||
(provider) =>
|
||||
EDIT_ALLOWS_CONTEXT_PROVIDERS.includes(provider.title),
|
||||
)}
|
||||
historyKey="edit"
|
||||
availableSlashCommands={[]}
|
||||
isMainInput={true}
|
||||
onEnter={async function (
|
||||
editorState: JSONContent,
|
||||
modifiers: InputModifiers,
|
||||
editor: Editor,
|
||||
): Promise<void> {
|
||||
const [_, __, prompt] = await resolveEditorContent(
|
||||
editorState,
|
||||
{
|
||||
noContext: true,
|
||||
useCodebase: false,
|
||||
},
|
||||
ideMessenger,
|
||||
[],
|
||||
);
|
||||
ideMessenger.request("edit/sendPrompt", {
|
||||
prompt,
|
||||
range: editModeState.highlightedCode,
|
||||
});
|
||||
dispatch(submitEdit(prompt));
|
||||
|
||||
// Move cursor to end of editor (it's already focused)
|
||||
editor.commands.selectTextblockEnd();
|
||||
}}
|
||||
></TipTapEditor>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{["accepting", "streaming"].includes(editModeState.editStatus) && (
|
||||
<div className="my-2 flex w-full">
|
||||
<AcceptRejectButton
|
||||
disabled={editModeState.editStatus !== "accepting"}
|
||||
backgroundColor="#dc354588"
|
||||
onClick={() => {
|
||||
ideMessenger.request("edit/acceptReject", {
|
||||
accept: false,
|
||||
onlyFirst: false,
|
||||
filepath: editModeState.highlightedCode.filepath,
|
||||
});
|
||||
dispatch(setEditDone());
|
||||
}}
|
||||
>
|
||||
{getMetaKeyLabel()}⇧⌫ Reject all
|
||||
</AcceptRejectButton>
|
||||
<AcceptRejectButton
|
||||
disabled={editModeState.editStatus !== "accepting"}
|
||||
backgroundColor="#28a74588"
|
||||
onClick={() => {
|
||||
ideMessenger.request("edit/acceptReject", {
|
||||
accept: true,
|
||||
onlyFirst: false,
|
||||
filepath: editModeState.highlightedCode.filepath,
|
||||
});
|
||||
dispatch(setEditDone());
|
||||
}}
|
||||
>
|
||||
{getMetaKeyLabel()}⇧⏎ Accept all
|
||||
</AcceptRejectButton>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="mt-2">
|
||||
<NewSessionButton
|
||||
onClick={async () => {
|
||||
dispatch(setEditDone());
|
||||
}}
|
||||
className="mr-auto flex items-center gap-2"
|
||||
>
|
||||
<ArrowLeftIcon width="11px" height="11px" />
|
||||
Back to chat
|
||||
</NewSessionButton>
|
||||
</div>
|
||||
</TopDiv>
|
||||
</>
|
||||
);
|
||||
}
|
||||
export default Edit;
|
||||
|
|
@ -23,13 +23,13 @@ import {
|
|||
defaultBorderRadius,
|
||||
lightGray,
|
||||
vscBackground,
|
||||
vscForeground,
|
||||
} from "../../components";
|
||||
import { ChatScrollAnchor } from "../../components/ChatScrollAnchor";
|
||||
import StepContainer from "../../components/gui/StepContainer";
|
||||
import TimelineItem from "../../components/gui/TimelineItem";
|
||||
import ContinueInputBox from "../../components/mainInput/ContinueInputBox";
|
||||
import { defaultInputModifiers } from "../../components/mainInput/inputModifiers";
|
||||
import { NewSessionButton } from "../../components/mainInput/NewSessionButton";
|
||||
import { TutorialCard } from "../../components/mainInput/TutorialCard";
|
||||
import {
|
||||
OnboardingCard,
|
||||
|
|
@ -84,11 +84,15 @@ const StopButton = styled.div`
|
|||
padding: 4px 8px;
|
||||
color: ${lightGray};
|
||||
cursor: pointer;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
box-shadow:
|
||||
0 4px 6px rgba(0, 0, 0, 0.1),
|
||||
0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
transition: box-shadow 0.3s ease;
|
||||
|
||||
&:hover {
|
||||
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15), 0 3px 6px rgba(0, 0, 0, 0.1);
|
||||
box-shadow:
|
||||
0 6px 8px rgba(0, 0, 0, 0.15),
|
||||
0 3px 6px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
`;
|
||||
|
||||
|
|
@ -105,26 +109,6 @@ const StepsDiv = styled.div`
|
|||
}
|
||||
`;
|
||||
|
||||
const NewSessionButton = styled.div`
|
||||
width: fit-content;
|
||||
margin-right: auto;
|
||||
margin-left: 6px;
|
||||
margin-top: 2px;
|
||||
margin-bottom: 8px;
|
||||
font-size: ${getFontSize() - 2}px;
|
||||
|
||||
border-radius: ${defaultBorderRadius};
|
||||
padding: 2px 6px;
|
||||
color: ${lightGray};
|
||||
|
||||
&:hover {
|
||||
background-color: ${lightGray}33;
|
||||
color: ${vscForeground};
|
||||
}
|
||||
|
||||
cursor: pointer;
|
||||
`;
|
||||
|
||||
function fallbackRender({ error, resetErrorBoundary }: any) {
|
||||
// Call resetErrorBoundary() to reset the error boundary and retry the render.
|
||||
|
||||
|
|
@ -234,7 +218,7 @@ export function Chat() {
|
|||
if (currentCount === 300) {
|
||||
dispatch(
|
||||
setDialogMessage(
|
||||
<div className="text-center p-4">
|
||||
<div className="p-4 text-center">
|
||||
👋 Thanks for using Continue. We are always trying to improve
|
||||
and love hearing from users. If you're interested in speaking,
|
||||
enter your name and email. We won't use this information for
|
||||
|
|
@ -250,7 +234,7 @@ export function Chat() {
|
|||
});
|
||||
dispatch(
|
||||
setDialogMessage(
|
||||
<div className="text-center p-4">
|
||||
<div className="p-4 text-center">
|
||||
Thanks! We'll be in touch soon.
|
||||
</div>,
|
||||
),
|
||||
|
|
@ -331,7 +315,7 @@ export function Chat() {
|
|||
onScroll={handleScroll}
|
||||
showScrollbar={state.config.ui?.showChatScrollbar || false}
|
||||
>
|
||||
<div className="max-w-3xl m-auto">
|
||||
<div className="m-auto max-w-3xl">
|
||||
<StepsDiv>
|
||||
{state.history.map((item, index: number) => (
|
||||
<Fragment key={item.message.id}>
|
||||
|
|
@ -447,14 +431,14 @@ export function Chat() {
|
|||
<br />
|
||||
</>
|
||||
) : state.history.length > 0 ? (
|
||||
<div className="mt-2 hidden xs:inline">
|
||||
<div className="xs:inline mt-2 hidden">
|
||||
<NewSessionButton
|
||||
onClick={() => {
|
||||
saveSession();
|
||||
}}
|
||||
className="mr-auto"
|
||||
>
|
||||
<span className="hidden xs:inline">
|
||||
<span className="xs:inline hidden">
|
||||
New Session ({getMetaKeyLabel()} {isJetBrains() ? "J" : "L"})
|
||||
</span>
|
||||
</NewSessionButton>{" "}
|
||||
|
|
@ -462,7 +446,7 @@ export function Chat() {
|
|||
) : (
|
||||
<>
|
||||
{getLastSessionId() ? (
|
||||
<div className="mt-2 hidden xs:inline">
|
||||
<div className="xs:inline mt-2 hidden">
|
||||
<NewSessionButton
|
||||
onClick={async () => {
|
||||
loadLastSession().catch((e) =>
|
||||
|
|
@ -471,20 +455,20 @@ export function Chat() {
|
|||
}}
|
||||
className="mr-auto flex items-center gap-2"
|
||||
>
|
||||
<ArrowLeftIcon className="w-3 h-3" />
|
||||
<ArrowLeftIcon className="h-3 w-3" />
|
||||
Last Session
|
||||
</NewSessionButton>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{onboardingCard.show && (
|
||||
<div className="mt-10 mx-2">
|
||||
<div className="mx-2 mt-10">
|
||||
<OnboardingCard activeTab={onboardingCard.activeTab} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showTutorialCard !== false && !onboardingCard.open && (
|
||||
<div className="flex justify-center w-full">
|
||||
<div className="flex w-full justify-center">
|
||||
<TutorialCard onClose={closeTutorialCard} />
|
||||
</div>
|
||||
)}
|
||||
|
|
@ -501,7 +485,7 @@ export function Chat() {
|
|||
|
||||
{ttsActive && (
|
||||
<StopButton
|
||||
className="mt-2 mb-4"
|
||||
className="mb-4 mt-2"
|
||||
onClick={() => {
|
||||
ideMessenger.post("tts/kill", undefined);
|
||||
}}
|
||||
|
|
@ -511,7 +495,7 @@ export function Chat() {
|
|||
)}
|
||||
{active && (
|
||||
<StopButton
|
||||
className="mt-auto mb-4"
|
||||
className="mb-4 mt-auto"
|
||||
onClick={() => {
|
||||
dispatch(setInactive());
|
||||
if (
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Chat } from "./Chat";
|
||||
import { History } from "../../components/History";
|
||||
import { Chat } from "./Chat";
|
||||
|
||||
export default function GUI() {
|
||||
return (
|
||||
|
|
|
|||
60
gui/src/redux/slices/editModeState.ts
Normal file
60
gui/src/redux/slices/editModeState.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { MessageContent } from "core";
|
||||
import { RangeInFileWithContents } from "core/commands/util";
|
||||
import { EditModeArgs } from "core/protocol/ideWebview";
|
||||
type EditStatus = "not-started" | "streaming" | "accepting" | "done";
|
||||
interface EditModeState {
|
||||
highlightedCode?: RangeInFileWithContents;
|
||||
editStatus: EditStatus;
|
||||
previousInputs: MessageContent[];
|
||||
}
|
||||
|
||||
const initialState: EditModeState = {
|
||||
editStatus: "not-started",
|
||||
previousInputs: [],
|
||||
};
|
||||
|
||||
export const editModeStateSlice = createSlice({
|
||||
name: "editModeState",
|
||||
initialState,
|
||||
reducers: {
|
||||
startEditMode: (state, { payload }: PayloadAction<EditModeArgs>) => {
|
||||
state.highlightedCode = payload.highlightedCode;
|
||||
state.editStatus = "not-started";
|
||||
state.previousInputs = [];
|
||||
},
|
||||
submitEdit: (state, { payload }: PayloadAction<MessageContent>) => {
|
||||
state.previousInputs.push(payload);
|
||||
state.editStatus = "streaming";
|
||||
},
|
||||
setEditStatus: (state, { payload }: PayloadAction<EditStatus>) => {
|
||||
// Only allow valid transitions
|
||||
const currentStatus = state.editStatus;
|
||||
if (currentStatus === "not-started" && payload === "streaming") {
|
||||
state.editStatus = payload;
|
||||
} else if (currentStatus === "streaming" && payload === "accepting") {
|
||||
state.editStatus = payload;
|
||||
} else if (currentStatus === "accepting" && payload === "done") {
|
||||
state.editStatus = payload;
|
||||
} else if (currentStatus === "done" && payload === "not-started") {
|
||||
state.editStatus = payload;
|
||||
}
|
||||
},
|
||||
addPreviousInput: (state, { payload }: PayloadAction<MessageContent>) => {
|
||||
state.previousInputs.push(payload);
|
||||
},
|
||||
setEditDone: (state) => {
|
||||
state.editStatus = "done";
|
||||
state.previousInputs = [];
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
startEditMode,
|
||||
setEditStatus,
|
||||
addPreviousInput,
|
||||
setEditDone,
|
||||
submitEdit,
|
||||
} = editModeStateSlice.actions;
|
||||
export default editModeStateSlice.reducer;
|
||||
|
|
@ -5,21 +5,6 @@ import {
|
|||
SlashCommandDescription,
|
||||
} from "core";
|
||||
|
||||
const TEST_SLASH_COMMANDS = [
|
||||
{
|
||||
name: "edit",
|
||||
description: "Edit the code",
|
||||
},
|
||||
{
|
||||
name: "cmd",
|
||||
description: "Generate a command",
|
||||
},
|
||||
{
|
||||
name: "help",
|
||||
description: "Get help using Continue",
|
||||
},
|
||||
];
|
||||
|
||||
type ServerState = {
|
||||
meilisearchUrl: string | undefined;
|
||||
slashCommands: SlashCommandDescription[];
|
||||
|
|
|
|||
|
|
@ -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[];
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { createTransform, persistReducer, persistStore } from "redux-persist";
|
|||
import { createFilter } from "redux-persist-transform-filter";
|
||||
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";
|
||||
import storage from "redux-persist/lib/storage";
|
||||
import editModeStateReducer from "./slices/editModeState";
|
||||
|
||||
export interface ChatMessage {
|
||||
role: "system" | "user" | "assistant";
|
||||
|
|
@ -21,6 +22,7 @@ const rootReducer = combineReducers({
|
|||
misc: miscReducer,
|
||||
uiState: uiStateReducer,
|
||||
serverState: serverStateReducer,
|
||||
editModeState: editModeStateReducer,
|
||||
});
|
||||
|
||||
export type RootState = ReturnType<typeof rootReducer>;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ type LocalStorageTypes = {
|
|||
ftc: number;
|
||||
fontSize: number;
|
||||
lastSessionId: string | undefined;
|
||||
inputHistory: JSONContent[];
|
||||
[key: `inputHistory_${string}`]: JSONContent[];
|
||||
extensionVersion: string;
|
||||
indexingState: IndexingProgressUpdate;
|
||||
showTutorialCard: boolean;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue