Changesets · Branches · Tags · Compare
| Changeset | c16c1eb07935ec6a61b446fc7876c20fe4f0e1f6e398ecab9d71e23113e58326 |
|---|---|
| Author | Fred Bricon <fbricon@gmail.com> · 2025-07-18 19:08 +02:00 |
| Committer | Fred Bricon <fbricon@gmail.com> · 2025-09-09 18:19 +02:00 |
| Parents | 174c272aba6c |
3 files changed
modified extensions/vscode/e2e/tests/KeyboardShortcuts.test.ts +66 −5
| @@ -4,12 +4,12 @@ | ||
| 4 | 4 | InputBox, |
| 5 | 5 | Key, |
| 6 | 6 | TextEditor, |
| 7 | + until, | |
| 7 | 8 | VSBrowser, |
| 8 | 9 | WebDriver, |
| 9 | 10 | WebElement, |
| 10 | 11 | WebView, |
| 11 | 12 | Workbench, |
| 12 | - until, | |
| 13 | 13 | } from "vscode-extension-tester"; |
| 14 | 14 | |
| 15 | 15 | import { GlobalActions } from "../actions/Global.actions"; |
| @@ -47,11 +47,31 @@ | ||
| 47 | 47 | |
| 48 | 48 | afterEach(async function () { |
| 49 | 49 | this.timeout(DEFAULT_TIMEOUT.XL * 1000); |
| 50 | + await cleanupChat(); | |
| 50 | 51 | await view.switchBack(); |
| 51 | 52 | await editor.clearText(); |
| 52 | 53 | await new EditorView().closeAllEditors(); |
| 53 | 54 | }); |
| 54 | 55 | |
| 56 | + async function cleanupChat(chatInput?: WebElement) { | |
| 57 | + try { | |
| 58 | + if (!chatInput) { | |
| 59 | + chatInput = await TestUtils.waitForSuccess(async () => { | |
| 60 | + return GUISelectors.getMessageInputFieldAtIndex(view, 0); | |
| 61 | + }); | |
| 62 | + } | |
| 63 | + if ( | |
| 64 | + chatInput && | |
| 65 | + (await chatInput.isDisplayed()) && | |
| 66 | + (await chatInput.isEnabled()) | |
| 67 | + ) { | |
| 68 | + await chatInput.clear(); | |
| 69 | + } | |
| 70 | + } catch (e) { | |
| 71 | + console.error(`Failed to clear chat: ${e}`); | |
| 72 | + } | |
| 73 | + } | |
| 74 | + | |
| 55 | 75 | it("Should correctly undo and redo using keyboard shortcuts when writing a chat message", async () => { |
| 56 | 76 | await GUIActions.executeFocusContinueInputShortcut(driver); |
| 57 | 77 | ({ view } = await GUIActions.switchToReactIframe()); |
| @@ -105,10 +125,8 @@ | ||
| 105 | 125 | ); |
| 106 | 126 | }).timeout(DEFAULT_TIMEOUT.XL); |
| 107 | 127 | |
| 108 | - it("Should not create a code block when Cmd+L is pressed without text highlighted", async () => { | |
| 109 | - const text = "Hello, world!"; | |
| 110 | - | |
| 111 | - await editor.setText(text); | |
| 128 | + it("Should not create a code block when Cmd+L is pressed on an empty document", async () => { | |
| 129 | + expect((await editor.getText()).trim()).to.equal(""); | |
| 112 | 130 | |
| 113 | 131 | await GUIActions.executeFocusContinueInputShortcut(driver); |
| 114 | 132 | |
| @@ -174,6 +192,9 @@ | ||
| 174 | 192 | |
| 175 | 193 | await driver.wait(until.elementIsNotVisible(textInput), DEFAULT_TIMEOUT.XS); |
| 176 | 194 | expect(await textInput.isDisplayed()).to.equal(false); |
| 195 | + | |
| 196 | + // Make sure the view is visible again, so it can be cleared in afterEach() | |
| 197 | + await GUIActions.executeFocusContinueInputShortcut(driver); | |
| 177 | 198 | }).timeout(DEFAULT_TIMEOUT.XL); |
| 178 | 199 | |
| 179 | 200 | it("Should create a code block when Cmd+L is pressed with text highlighted", async () => { |
| @@ -197,4 +218,44 @@ | ||
| 197 | 218 | |
| 198 | 219 | await GUIActions.executeFocusContinueInputShortcut(driver); |
| 199 | 220 | }).timeout(DEFAULT_TIMEOUT.XL); |
| 221 | + | |
| 222 | + it("Should create a code block with the whole file when Cmd+L is pressed on an empty line", async () => { | |
| 223 | + const text = "Hello,\n\n\nworld!"; | |
| 224 | + | |
| 225 | + await editor.setText(text); | |
| 226 | + await editor.moveCursor(2, 1); //Move cursor to an empty line | |
| 227 | + | |
| 228 | + await GUIActions.executeFocusContinueInputShortcut(driver); | |
| 229 | + | |
| 230 | + ({ view } = await GUIActions.switchToReactIframe()); | |
| 231 | + | |
| 232 | + const codeBlock = await TestUtils.waitForSuccess(() => | |
| 233 | + GUISelectors.getInputBoxCodeBlockAtIndex(view, 0), | |
| 234 | + ); | |
| 235 | + const codeblockContent = await codeBlock.getAttribute( | |
| 236 | + "data-codeblockcontent", | |
| 237 | + ); | |
| 238 | + | |
| 239 | + expect(codeblockContent).to.equal(text); | |
| 240 | + }); | |
| 241 | + | |
| 242 | + it("Should create a code block when Cmd+L is pressed on a non-empty line", async () => { | |
| 243 | + const text = "Hello, world!"; | |
| 244 | + | |
| 245 | + await editor.setText(text); | |
| 246 | + await editor.moveCursor(1, 7); //Move cursor to the 1st space | |
| 247 | + | |
| 248 | + await GUIActions.executeFocusContinueInputShortcut(driver); | |
| 249 | + | |
| 250 | + ({ view } = await GUIActions.switchToReactIframe()); | |
| 251 | + | |
| 252 | + const codeBlock = await TestUtils.waitForSuccess(() => | |
| 253 | + GUISelectors.getInputBoxCodeBlockAtIndex(view, 0), | |
| 254 | + ); | |
| 255 | + const codeblockContent = await codeBlock.getAttribute( | |
| 256 | + "data-codeblockcontent", | |
| 257 | + ); | |
| 258 | + | |
| 259 | + expect(codeblockContent).to.equal(text); | |
| 260 | + }).timeout(DEFAULT_TIMEOUT.XL); | |
| 200 | 261 | }); |
modified extensions/vscode/package.json +2 −3
| @@ -540,13 +540,12 @@ | ||
| 540 | 540 | "continue.continueSubMenu": [ |
| 541 | 541 | { |
| 542 | 542 | "command": "continue.focusContinueInputWithoutClear", |
| 543 | - "group": "Continue", | |
| 544 | - "when": "editorHasSelection" | |
| 543 | + "group": "Continue" | |
| 545 | 544 | }, |
| 546 | 545 | { |
| 547 | 546 | "command": "continue.focusEdit", |
| 548 | 547 | "group": "Continue", |
| 549 | - "when": "editorHasSelection && !editorReadonly" | |
| 548 | + "when": "!editorReadonly" | |
| 550 | 549 | } |
| 551 | 550 | ], |
| 552 | 551 | "explorer/context": [ |
modified extensions/vscode/src/util/addCode.ts +38 −18
| @@ -36,22 +36,38 @@ | ||
| 36 | 36 | }; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | - if (selection.isEmpty && !allowEmpty) { | |
| 39 | + if ((selection.isEmpty && !allowEmpty) || isEmptyFile(editor.document)) { | |
| 40 | 40 | return null; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - let selectionRange = new vscode.Range(selection.start, selection.end); | |
| 44 | - const document = editor.document; | |
| 45 | - // Select the context from the beginning of the selection start line to the selection start position | |
| 46 | - const beginningOfSelectionStartLine = selection.start.with(undefined, 0); | |
| 47 | - const textBeforeSelectionStart = document.getText( | |
| 48 | - new vscode.Range(beginningOfSelectionStartLine, selection.start), | |
| 49 | - ); | |
| 50 | - // If there are only whitespace before the start of the selection, include the indentation | |
| 51 | - if (textBeforeSelectionStart.trim().length === 0) { | |
| 52 | - selectionRange = selectionRange.with({ | |
| 53 | - start: beginningOfSelectionStartLine, | |
| 54 | - }); | |
| 43 | + let selectionRange: vscode.Range | undefined; | |
| 44 | + // if the selection is empty and document is not empty, select the whole document | |
| 45 | + if (selection.isEmpty) { | |
| 46 | + selectionRange = new vscode.Range( | |
| 47 | + new vscode.Position(0, 0), | |
| 48 | + new vscode.Position( | |
| 49 | + editor.document.lineCount - 1, | |
| 50 | + editor.document.lineAt( | |
| 51 | + editor.document.lineCount - 1, | |
| 52 | + ).range.end.character, | |
| 53 | + ), | |
| 54 | + ); | |
| 55 | + } | |
| 56 | + | |
| 57 | + if (!selectionRange) { | |
| 58 | + selectionRange = new vscode.Range(selection.start, selection.end); | |
| 59 | + const document = editor.document; | |
| 60 | + // Select the context from the beginning of the selection start line to the selection start position | |
| 61 | + const beginningOfSelectionStartLine = selection.start.with(undefined, 0); | |
| 62 | + const textBeforeSelectionStart = document.getText( | |
| 63 | + new vscode.Range(beginningOfSelectionStartLine, selection.start), | |
| 64 | + ); | |
| 65 | + // If there are only whitespace before the start of the selection, include the indentation | |
| 66 | + if (textBeforeSelectionStart.trim().length === 0) { | |
| 67 | + selectionRange = selectionRange.with({ | |
| 68 | + start: beginningOfSelectionStartLine, | |
| 69 | + }); | |
| 70 | + } | |
| 55 | 71 | } |
| 56 | 72 | |
| 57 | 73 | const contents = editor.document.getText(selectionRange); |
| @@ -61,12 +77,12 @@ | ||
| 61 | 77 | contents, |
| 62 | 78 | range: { |
| 63 | 79 | start: { |
| 64 | - line: selection.start.line, | |
| 65 | - character: selection.start.character, | |
| 80 | + line: selectionRange.start.line, | |
| 81 | + character: selectionRange.start.character, | |
| 66 | 82 | }, |
| 67 | 83 | end: { |
| 68 | - line: selection.end.line, | |
| 69 | - character: selection.end.character, | |
| 84 | + line: selectionRange.end.line, | |
| 85 | + character: selectionRange.end.character, | |
| 70 | 86 | }, |
| 71 | 87 | }, |
| 72 | 88 | }; |
| @@ -78,7 +94,7 @@ | ||
| 78 | 94 | export async function addHighlightedCodeToContext( |
| 79 | 95 | webviewProtocol: VsCodeWebviewProtocol | undefined, |
| 80 | 96 | ) { |
| 81 | - const rangeInFileWithContents = getRangeInFileWithContents(); | |
| 97 | + const rangeInFileWithContents = getRangeInFileWithContents(true); | |
| 82 | 98 | if (rangeInFileWithContents) { |
| 83 | 99 | webviewProtocol?.request("highlightedCode", { |
| 84 | 100 | rangeInFileWithContents, |
| @@ -129,6 +145,10 @@ | ||
| 129 | 145 | }); |
| 130 | 146 | } |
| 131 | 147 | |
| 148 | +export function isEmptyFile(document: vscode.TextDocument) { | |
| 149 | + return document.lineCount === 1 && document.lineAt(0).range.isEmpty; | |
| 150 | +} | |
| 151 | + | |
| 132 | 152 | export function addCodeToContextFromRange( |
| 133 | 153 | range: vscode.Range, |
| 134 | 154 | webviewProtocol: VsCodeWebviewProtocol, |