Skip to content

Commit

Permalink
Merge pull request #3523 from continuedev/tomasz/fix-tiptap-undo-redo
Browse files Browse the repository at this point in the history
fix: tip tap undo and redo
  • Loading branch information
tomasz-stefaniak authored Dec 24, 2024
2 parents 450880e + e45aa16 commit 8ef4681
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
59 changes: 56 additions & 3 deletions extensions/vscode/e2e/tests/KeyboardShortcuts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import {
WebView,
WebElement,
until,
Key,
} from "vscode-extension-tester";
import { DEFAULT_TIMEOUT } from "../constants";
import { GUISelectors } from "../selectors/GUI.selectors";
import { GUIActions } from "../actions/GUI.actions";
import { expect } from "chai";
import { TestUtils } from "../TestUtils";
import { Test } from "mocha";
import { KeyboardShortcutsActions } from "../actions/KeyboardShortcuts.actions";

describe("Cmd+L Shortcut Test", () => {
describe("Keyboard Shortcuts", () => {
let driver: WebDriver;
let editor: TextEditor;
let view: WebView;
Expand Down Expand Up @@ -49,6 +49,59 @@ describe("Cmd+L Shortcut Test", () => {
await new EditorView().closeAllEditors();
});

it("Should correctly undo and redo using keyboard shortcuts when writing a chat message", async () => {
await GUIActions.executeFocusContinueInputShortcut(driver);
({ view } = await GUIActions.switchToReactIframe());
const chatInput = await TestUtils.waitForSuccess(async () => {
return GUISelectors.getMessageInputFieldAtIndex(view, 0);
});

await chatInput.sendKeys("HELLO ");
await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS);

await chatInput.sendKeys("WORLD ");
await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS);

await chatInput.sendKeys("HELLO ");
await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS);

await chatInput.sendKeys("CONTINUE");
await TestUtils.waitForTimeout(DEFAULT_TIMEOUT.XS);

await chatInput.sendKeys(TestUtils.osControlKey + "z");
await driver.wait(
until.elementTextIs(chatInput, "HELLO WORLD"),
DEFAULT_TIMEOUT.SM,
);

await chatInput.sendKeys(TestUtils.osControlKey + "z");
await driver.wait(until.elementTextIs(chatInput, ""), DEFAULT_TIMEOUT.SM);

await chatInput.sendKeys(Key.SHIFT + TestUtils.osControlKey + "z");
await driver.wait(
until.elementTextIs(chatInput, "HELLO"),
DEFAULT_TIMEOUT.SM,
);

await chatInput.sendKeys(Key.SHIFT + TestUtils.osControlKey + "z");
await driver.wait(
until.elementTextIs(chatInput, "HELLO WORLD"),
DEFAULT_TIMEOUT.SM,
);

await chatInput.sendKeys(Key.SHIFT + TestUtils.osControlKey + "z");
await driver.wait(
until.elementTextIs(chatInput, "HELLO WORLD HELLO"),
DEFAULT_TIMEOUT.SM,
);

await chatInput.sendKeys(Key.SHIFT + TestUtils.osControlKey + "z");
await driver.wait(
until.elementTextIs(chatInput, "HELLO WORLD HELLO CONTINUE"),
DEFAULT_TIMEOUT.SM,
);
}).timeout(DEFAULT_TIMEOUT.XL);

it("Should not create a code block when Cmd+L is pressed without text highlighted", async () => {
const text = "Hello, world!";

Expand Down Expand Up @@ -118,7 +171,7 @@ describe("Cmd+L Shortcut Test", () => {

await driver.wait(until.elementIsNotVisible(textInput), DEFAULT_TIMEOUT.XS);
expect(await textInput.isDisplayed()).to.equal(false);
}).timeout(DEFAULT_TIMEOUT.XL * 1000);
}).timeout(DEFAULT_TIMEOUT.XL);

it("Should create a code block when Cmd+L is pressed with text highlighted", async () => {
const text = "Hello, world!";
Expand Down
13 changes: 13 additions & 0 deletions gui/src/components/mainInput/handleMetaKeyIssues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export const handleVSCMetaKeyIssues = async (
x: () => handleCutOperation(text, editor),
c: () => handleCopyOperation(text),
v: () => handlePasteOperation(editor),
z: () => {
return e.shiftKey
? handleRedoOperation(editor)
: handleUndoOperation(editor);
},
};

if (e.key in handlers) {
Expand Down Expand Up @@ -130,3 +135,11 @@ export const handlePasteOperation = async (editor: Editor) => {
document.execCommand("paste");
}
};

export const handleUndoOperation = async (editor: Editor) => {
editor.commands.undo();
};

export const handleRedoOperation = async (editor: Editor) => {
editor.commands.redo();
};

0 comments on commit 8ef4681

Please sign in to comment.