Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions packages/common/src/types/TextEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,15 +250,25 @@ export interface EditableTextEditor extends TextEditor {
*/
gitRevert(range?: Range): Promise<void>;

/**
* Git stage file
*/
gitStageFile(): Promise<void>;

/**
* Git unstage file
*/
gitUnstageFile(): Promise<void>;

/**
* Git stage range
* @param range A {@link Range range}
*/
gitStage(range?: Range): Promise<void>;
gitStageRange(range?: Range): Promise<void>;

/**
* Git unstage range
* @param range A {@link Range range}
*/
gitUnstage(range?: Range): Promise<void>;
gitUnstageRange(range?: Range): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ abstract class SimpleIdeCommandAction {
callback(
editor,
acceptsLocation ? targets.map((t) => t.contentRange) : undefined,
rangeIsEntireDocument(targets),
this.command,
),
setSelection: !acceptsLocation,
Expand Down Expand Up @@ -151,6 +152,7 @@ export class GitUnstage extends SimpleIdeCommandAction {
function callback(
editor: EditableTextEditor,
ranges: Range[] | undefined,
rangeIsEntireDocument: boolean,
command: CommandId,
): Promise<void> {
switch (command) {
Expand Down Expand Up @@ -192,12 +194,25 @@ function callback(
case "gitRevert":
return editor.gitRevert(ranges?.[0]);
case "gitStage":
return editor.gitStage(ranges?.[0]);
if (rangeIsEntireDocument) {
return editor.gitStageFile();
}
return editor.gitStageRange(ranges?.[0]);
case "gitUnstage":
return editor.gitUnstage(ranges?.[0]);
if (rangeIsEntireDocument) {
return editor.gitUnstageFile();
}
return editor.gitUnstageRange(ranges?.[0]);

// Unsupported as simple action
case "highlight":
throw Error("Highlight command not supported as simple action");
}
}

function rangeIsEntireDocument(targets: Target[]): boolean {
return (
targets.length === 1 &&
targets[0].contentRange.isRangeEqual(targets[0].editor.document.range)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,19 @@ export class TalonJsEditor implements EditableTextEditor {
throw Error("gitRevert not implemented");
}

public async gitStage(_range?: Range): Promise<void> {
throw Error("gitStage not implemented");
public async gitStageFile(): Promise<void> {
throw Error("gitStageFile not implemented");
}

public async gitUnstage(_range?: Range): Promise<void> {
throw Error("gitUnstage not implemented");
public async gitUnstageFile(): Promise<void> {
throw Error("gitUnstageFile not implemented");
}

public async gitStageRange(_range?: Range): Promise<void> {
throw Error("gitStageRange not implemented");
}

public async gitUnstageRange(_range?: Range): Promise<void> {
throw Error("gitUnstageRange not implemented");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,19 @@ export class VscodeTextEditorImpl implements EditableTextEditor {
await vscode.commands.executeCommand("git.revertSelectedRanges");
}

public async gitStage(_range?: Range): Promise<void> {
public async gitStageFile(): Promise<void> {
await vscode.commands.executeCommand("git.stage");
}

public async gitUnstageFile(): Promise<void> {
await vscode.commands.executeCommand("git.unstage");
}

public async gitStageRange(_range?: Range): Promise<void> {
await vscode.commands.executeCommand("git.stageSelectedRanges");
}

public async gitUnstage(_range?: Range): Promise<void> {
public async gitUnstageRange(_range?: Range): Promise<void> {
await vscode.commands.executeCommand("git.unstageSelectedRanges");
}
}
16 changes: 12 additions & 4 deletions packages/neovim-common/src/ide/neovim/NeovimTextEditorImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,19 @@ export class NeovimTextEditorImpl implements EditableTextEditor {
throw Error("gitRevert Not implemented");
}

public async gitStage(_range?: Range): Promise<void> {
throw Error("gitStage Not implemented");
public async gitStageFile(): Promise<void> {
throw Error("gitStageFile not implemented");
}

public async gitUnstage(_range?: Range): Promise<void> {
throw Error("gitUnstage Not implemented");
public async gitUnstageFile(): Promise<void> {
throw Error("gitUnstageFile not implemented");
}

public async gitStageRange(_range?: Range): Promise<void> {
throw Error("gitStageRange not implemented");
}

public async gitUnstageRange(_range?: Range): Promise<void> {
throw Error("gitUnstageRange not implemented");
}
}
Loading