Skip to content

Commit 479f80b

Browse files
Fix "pour" across split (#1219)
- This one most likely broke in #1143, but I'm not certain ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [ ] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [ ] I have not broken the cheatsheet Co-authored-by: Andreas Arvidsson <[email protected]>
1 parent b5e2d2f commit 479f80b

File tree

7 files changed

+69
-16
lines changed

7 files changed

+69
-16
lines changed

src/apps/cursorless-vscode-e2e/suite/fold.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ suite("fold", async function () {
1212
});
1313

1414
async function foldMade() {
15-
const editor = await openNewEditor("function myFunk() {\n\n}", "typescript");
15+
const editor = await openNewEditor("function myFunk() {\n\n}", {
16+
languageId: "typescript",
17+
});
1618

1719
await runCursorlessCommand({
1820
version: 1,
@@ -35,7 +37,9 @@ async function foldMade() {
3537
}
3638

3739
async function unfoldMade() {
38-
const editor = await openNewEditor("function myFunk() {\n\n}", "typescript");
40+
const editor = await openNewEditor("function myFunk() {\n\n}", {
41+
languageId: "typescript",
42+
});
3943
await vscode.commands.executeCommand("editor.fold", {
4044
selectionLines: [0],
4145
});

src/apps/cursorless-vscode-e2e/suite/followLink.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ suite("followLink", async function () {
1414
});
1515

1616
async function followDefinition() {
17-
const editor = await openNewEditor(
18-
"const foo = 'hello';\nconst bar = foo;",
19-
"typescript",
20-
);
17+
const editor = await openNewEditor("const foo = 'hello';\nconst bar = foo;", {
18+
languageId: "typescript",
19+
});
2120
await vscode.commands.executeCommand("revealLine", {
2221
lineNumber: 1,
2322
at: "top",

src/apps/cursorless-vscode-e2e/suite/keyboard/basic.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ async function checkKeyboardStartup() {
2929
async function basic() {
3030
const { graph } = (await getCursorlessApi()).testHelpers!;
3131

32-
const editor = await openNewEditor("function foo() {}\n", "typescript");
32+
const editor = await openNewEditor("function foo() {}\n", {
33+
languageId: "typescript",
34+
});
3335
await graph.hatTokenMap.addDecorations();
3436

3537
editor.selection = new vscode.Selection(1, 0, 1, 0);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { getCursorlessApi, openNewEditor } from "@cursorless/vscode-common";
2+
import * as assert from "assert";
3+
import { endToEndTestSetup } from "../endToEndTestSetup";
4+
import { runCursorlessCommand } from "../runCommand";
5+
6+
suite("Pour across split", async function () {
7+
endToEndTestSetup(this);
8+
9+
test("Pour across split", runTest);
10+
});
11+
12+
async function runTest() {
13+
const { graph } = (await getCursorlessApi()).testHelpers!;
14+
15+
const { document: document1 } = await openNewEditor("hello world");
16+
const { document: document2 } = await openNewEditor("", { openBeside: true });
17+
18+
await graph.hatTokenMap.addDecorations();
19+
20+
await runCursorlessCommand({
21+
version: 4,
22+
action: { name: "editNewLineAfter" },
23+
targets: [
24+
{
25+
type: "primitive",
26+
mark: {
27+
type: "decoratedSymbol",
28+
symbolColor: "default",
29+
character: "h",
30+
},
31+
},
32+
],
33+
usePrePhraseSnapshot: false,
34+
});
35+
36+
assert.deepStrictEqual(document1.getText(), "hello world\n");
37+
assert.deepStrictEqual(document2.getText(), "");
38+
}

src/apps/cursorless-vscode-e2e/suite/recorded.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ async function runTest(file: string, spyIde: SpyIDE) {
6868

6969
graph.editStyles.testDecorations = [];
7070

71-
const editor = await openNewEditor(
72-
fixture.initialState.documentContents,
73-
fixture.languageId,
74-
);
71+
const editor = await openNewEditor(fixture.initialState.documentContents, {
72+
languageId: fixture.languageId,
73+
});
7574

7675
// Override any user settings and make sure tests run with default tabs.
7776
editor.options = DEFAULT_TEXT_EDITOR_OPTIONS_FOR_TEST;

src/ide/vscode/VscodeTextEditorImpl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export class VscodeTextEditorImpl implements EditableTextEditor {
156156
if (ranges != null) {
157157
this.selections = ranges.map((range) => range.toSelection(false));
158158
}
159+
await this.focus();
159160
await vscode.commands.executeCommand("editor.action.insertLineAfter");
160161
}
161162

src/libs/vscode-common/testUtil/openNewEditor.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
11
import { getParseTreeApi } from "@cursorless/vscode-common";
22
import * as vscode from "vscode";
33

4+
interface NewEditorOptions {
5+
languageId?: string;
6+
openBeside?: boolean;
7+
}
8+
49
export async function openNewEditor(
510
content: string,
6-
language: string = "plaintext",
11+
{ languageId = "plaintext", openBeside = false }: NewEditorOptions = {},
712
) {
8-
await vscode.commands.executeCommand("workbench.action.closeAllEditors");
13+
if (!openBeside) {
14+
await vscode.commands.executeCommand("workbench.action.closeAllEditors");
15+
}
916

1017
const document = await vscode.workspace.openTextDocument({
11-
language,
18+
language: languageId,
1219
content,
1320
});
1421

15-
await (await getParseTreeApi()).loadLanguage(language);
22+
await (await getParseTreeApi()).loadLanguage(languageId);
1623

17-
const editor = await vscode.window.showTextDocument(document);
24+
const editor = await vscode.window.showTextDocument(
25+
document,
26+
openBeside ? vscode.ViewColumn.Beside : undefined,
27+
);
1828

1929
const eol = content.includes("\r\n")
2030
? vscode.EndOfLine.CRLF

0 commit comments

Comments
 (0)