Skip to content

Commit 7968fc3

Browse files
Reactivate reveal range on focus editor (#2437)
Was removed by mistake in 008baa1 ## Checklist - [/] 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
1 parent c2baf48 commit 7968fc3

File tree

4 files changed

+73
-1
lines changed

4 files changed

+73
-1
lines changed

packages/common/src/types/TextEditor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface TextEditor {
5555

5656
export interface SetSelectionsOpts {
5757
focusEditor?: boolean;
58+
revealRange?: boolean;
5859
}
5960

6061
export interface EditableTextEditor extends TextEditor {

packages/cursorless-engine/src/actions/CallbackAction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export class CallbackAction {
9393
if (options.setSelection) {
9494
await editableEditor.setSelections(targetSelections, {
9595
focusEditor: true,
96+
revealRange: false,
9697
});
9798
}
9899

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { openNewEditor } from "@cursorless/vscode-common";
2+
import * as vscode from "vscode";
3+
import { endToEndTestSetup } from "../endToEndTestSetup";
4+
import { runCursorlessCommand } from "@cursorless/vscode-common";
5+
import assert from "assert";
6+
7+
suite("revealRange", async function () {
8+
endToEndTestSetup(this);
9+
10+
test("pre file", preFile);
11+
test("post file", postFile);
12+
});
13+
14+
const content = new Array(100).fill("line").join("\n");
15+
16+
async function preFile() {
17+
const editor = await openNewEditor(content);
18+
const startLine = editor.document.lineCount - 1;
19+
editor.selections = [new vscode.Selection(startLine, 0, startLine, 0)];
20+
editor.revealRange(new vscode.Range(startLine, 0, startLine, 0));
21+
22+
await runCursorlessCommand({
23+
version: 7,
24+
usePrePhraseSnapshot: false,
25+
action: {
26+
name: "setSelectionBefore",
27+
target: {
28+
type: "primitive",
29+
modifiers: [
30+
{ type: "containingScope", scopeType: { type: "document" } },
31+
],
32+
},
33+
},
34+
});
35+
36+
assert.equal(editor.visibleRanges.length, 1);
37+
// FIXME: Disabled to work around CI failure; see #2243
38+
// assert.equal(editor.visibleRanges[0].start.line, 0);
39+
}
40+
41+
async function postFile() {
42+
const editor = await openNewEditor(content);
43+
await vscode.commands.executeCommand("revealLine", {
44+
lineNumber: 1,
45+
at: "top",
46+
});
47+
editor.selections = [new vscode.Selection(0, 0, 0, 0)];
48+
49+
await runCursorlessCommand({
50+
version: 7,
51+
usePrePhraseSnapshot: false,
52+
action: {
53+
name: "setSelectionAfter",
54+
target: {
55+
type: "primitive",
56+
modifiers: [
57+
{ type: "containingScope", scopeType: { type: "document" } },
58+
],
59+
},
60+
},
61+
});
62+
63+
assert.equal(editor.visibleRanges.length, 1);
64+
// FIXME: Disabled to work around CI failure; see #2243
65+
// assert.equal(editor.visibleRanges[0].end.line, editor.document.lineCount - 1);
66+
}

packages/cursorless-vscode/src/ide/vscode/VscodeTextEditorImpl.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class VscodeTextEditorImpl implements EditableTextEditor {
5757

5858
async setSelections(
5959
rawSelections: Selection[],
60-
{ focusEditor = false }: SetSelectionsOpts = {},
60+
{ focusEditor = false, revealRange = true }: SetSelectionsOpts = {},
6161
): Promise<void> {
6262
const selections = uniqWithHash(
6363
rawSelections,
@@ -87,6 +87,10 @@ export class VscodeTextEditorImpl implements EditableTextEditor {
8787
this.editor.selections = selections;
8888
await vscodeFocusEditor(this);
8989
}
90+
91+
if (revealRange) {
92+
await this.revealRange(this.selections[0]);
93+
}
9094
}
9195

9296
get visibleRanges(): Range[] {

0 commit comments

Comments
 (0)