Skip to content

Commit 9c5d1bc

Browse files
simplification
1 parent 2b08c14 commit 9c5d1bc

1 file changed

Lines changed: 11 additions & 13 deletions

File tree

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ abstract class SimpleIdeCommandAction {
4646
callback: (editor, targets) =>
4747
callback(
4848
editor,
49-
targets.map((t) => t.contentRange),
50-
acceptsLocation,
49+
acceptsLocation ? targets.map((t) => t.contentRange) : undefined,
50+
rangeIsEntireDocument(targets),
5151
this.command,
5252
),
5353
setSelection: !acceptsLocation,
@@ -151,12 +151,10 @@ export class GitUnstage extends SimpleIdeCommandAction {
151151

152152
function callback(
153153
editor: EditableTextEditor,
154-
targetRanges: Range[],
155-
acceptsLocation: boolean,
154+
ranges: Range[] | undefined,
155+
rangeIsEntireDocument: boolean,
156156
command: CommandId,
157157
): Promise<void> {
158-
const ranges = acceptsLocation ? targetRanges : undefined;
159-
160158
switch (command) {
161159
// Multi target actions
162160
case "toggleLineComment":
@@ -196,12 +194,12 @@ function callback(
196194
case "gitRevert":
197195
return editor.gitRevert(ranges?.[0]);
198196
case "gitStage":
199-
if (rangeIsEntireDocument(editor, targetRanges)) {
197+
if (rangeIsEntireDocument) {
200198
return editor.gitStageFile();
201199
}
202200
return editor.gitStageRange(ranges?.[0]);
203201
case "gitUnstage":
204-
if (rangeIsEntireDocument(editor, targetRanges)) {
202+
if (rangeIsEntireDocument) {
205203
return editor.gitUnstageFile();
206204
}
207205
return editor.gitUnstageRange(ranges?.[0]);
@@ -212,9 +210,9 @@ function callback(
212210
}
213211
}
214212

215-
function rangeIsEntireDocument(
216-
editor: EditableTextEditor,
217-
ranges: Range[],
218-
): boolean {
219-
return ranges.length === 1 && ranges[0].isRangeEqual(editor.document.range);
213+
function rangeIsEntireDocument(targets: Target[]): boolean {
214+
return (
215+
targets.length === 1 &&
216+
targets[0].contentRange.isRangeEqual(targets[0].editor.document.range)
217+
);
220218
}

0 commit comments

Comments
 (0)