fix: open new session from any page

This commit is contained in:
tomasz-io 2024-12-20 11:48:33 -08:00
parent 4acb7a4992
commit 258bbc6b5c
7 changed files with 94 additions and 9 deletions

View file

@ -1,4 +1,11 @@
import { EditorView, WebView, WebDriver, Key } from "vscode-extension-tester";
import {
EditorView,
WebView,
WebDriver,
Key,
WebElement,
VSBrowser,
} from "vscode-extension-tester";
import { expect } from "chai";
import { GUIActions } from "../actions/GUI.actions";
import { GUISelectors } from "../selectors/GUI.selectors";
@ -12,6 +19,7 @@ describe("GUI Test", () => {
before(async function () {
this.timeout(DEFAULT_TIMEOUT.XL);
await GUIActions.moveContinueToSidebar(VSBrowser.instance.driver);
await GlobalActions.openTestWorkspace();
});
@ -184,6 +192,36 @@ describe("GUI Test", () => {
});
describe("Chat Paths", () => {
it("Open chat and type → open history → cmd+l → chat opens, empty and in focus", async () => {
const originalTextInput = await GUISelectors.getMessageInputFieldAtIndex(
view,
0,
);
await originalTextInput.click();
await originalTextInput.sendKeys("Hello");
expect(await originalTextInput.getText()).to.equal("Hello");
await view.switchBack();
await (await GUISelectors.getHistoryNavButton(view)).click();
await GUIActions.switchToReactIframe();
await view.switchBack();
await (await GUISelectors.getNewSessionNavButton(view)).click();
await GUIActions.switchToReactIframe();
const newTextInput = await TestUtils.waitForSuccess(() =>
GUISelectors.getMessageInputFieldAtIndex(view, 0),
);
const activeElement: WebElement = await driver.switchTo().activeElement();
const newTextInputHtml = await newTextInput.getAttribute("outerHTML");
const activeElementHtml = await activeElement.getAttribute("outerHTML");
expect(newTextInputHtml).to.equal(activeElementHtml);
const textInputValue = await newTextInput.getText();
expect(textInputValue).to.equal("");
}).timeout(DEFAULT_TIMEOUT.XL);
it("chat → history → chat", async () => {
const messagePair1 = TestUtils.generateTestMessagePair(1);
await GUIActions.sendMessage({

View file

@ -77,6 +77,8 @@ describe("Cmd+L Shortcut Test", () => {
expect(await textInput.isDisplayed()).to.equal(true);
await GUIActions.executeFocusContinueInputShortcut(driver);
await driver.wait(until.elementIsNotVisible(textInput), DEFAULT_TIMEOUT.XS);
expect(await textInput.isDisplayed()).to.equal(false);
}).timeout(DEFAULT_TIMEOUT.XL);

View file

@ -432,6 +432,7 @@ const getCommandsMap: (
core.invoke("context/indexDocs", { reIndex: true });
},
"continue.focusContinueInput": async () => {
// debugger;
const isContinueInputFocused = await sidebar.webviewProtocol.request(
"isContinueInputFocused",
undefined,
@ -466,6 +467,7 @@ const getCommandsMap: (
);
}
} else {
// debugger;
focusGUI();
sidebar.webviewProtocol?.request(
"focusContinueInputWithNewSession",

View file

@ -16,7 +16,7 @@ import { SubmenuContextProvidersProvider } from "./context/SubmenuContextProvide
const router = createMemoryRouter([
{
path: "/",
path: ROUTES.HOME,
element: <Layout />,
errorElement: <ErrorPage />,
children: [
@ -25,7 +25,7 @@ const router = createMemoryRouter([
element: <Chat />,
},
{
path: "/",
path: ROUTES.HOME,
element: <Chat />,
},
{

View file

@ -65,6 +65,44 @@ const Layout = () => {
const showDialog = useAppSelector((state) => state.ui.showDialog);
useWebviewListener(
"newSession",
async () => {
navigate(ROUTES.HOME);
await dispatch(
saveCurrentSession({
openNewSession: true,
}),
);
dispatch(exitEditMode());
},
[],
);
useWebviewListener(
"isContinueInputFocused",
async () => {
return false;
},
[location.pathname],
location.pathname === ROUTES.HOME,
);
useWebviewListener(
"focusContinueInputWithNewSession",
async () => {
navigate(ROUTES.HOME);
await dispatch(
saveCurrentSession({
openNewSession: true,
}),
);
dispatch(exitEditMode());
},
[location.pathname],
location.pathname === ROUTES.HOME,
);
useWebviewListener(
"openDialogMessage",
async (message) => {

View file

@ -647,6 +647,17 @@ function TipTapEditor(props: TipTapEditorProps) {
[props.onEnter, editor, props.isMainInput],
);
useEffect(() => {
if (props.isMainInput) {
/**
* I have a strong suspicion that many of the other focus
* commands are redundant, especially the ones inside
* useTimeout.
*/
editor.commands.focus();
}
}, [props.isMainInput, editor]);
// Re-focus main input after done generating
useEffect(() => {
if (editor && !isStreaming && props.isMainInput && document.hasFocus()) {

View file

@ -321,14 +321,8 @@ export function Chat() {
useWebviewListener(
"newSession",
async () => {
await dispatch(
saveCurrentSession({
openNewSession: true,
}),
);
// unwrapResult(response) // errors if session creation failed
mainTextInputRef.current?.focus?.();
dispatch(exitEditMode());
},
[mainTextInputRef],
);