Elffuss BraidHub

kikocis/continue public

main · 1.0 KiBRawPermalink
1import { Key, TextEditor, WebElement } from "vscode-extension-tester";
2
3export class KeyboardShortcutsActions {
4 /**
5 * For some reason Selenium-simulated keyboard shortcuts don't perfectly
6 * mimic the behavior of real shortcuts unless some text is highlighted first.
7 */
8 public static async HACK__typeWithSelect(editor: TextEditor, text: string) {
9 await editor.typeText(text);
10 await editor.selectText(text);
11 await editor.typeText(text);
12 }
13
14 /**
15 * Types each string in the array with a newline (Shift+Enter) between them.
16 * Optionally adds a final Enter key press to submit.
17 */
18 public static async typeWithNewlines({
19 input,
20 lines,
21 submit,
22 }: {
23 input: TextEditor | WebElement;
24 lines: string[];
25 submit?: boolean;
26 }) {
27 for (let i = 0; i < lines.length - 1; i++) {
28 await input.sendKeys(lines[i]);
29 await input.sendKeys(Key.chord(Key.SHIFT, Key.ENTER));
30 }
31 await input.sendKeys(lines[lines.length - 1]);
32 if (submit) {
33 await input.sendKeys(Key.ENTER);
34 }
35 }
36}