This commit is contained in:
Henning Dieterichs
2024-03-15 16:52:52 +01:00
committed by Henning Dieterichs
parent 15715aedf0
commit b7d35c8bdd
26 changed files with 800 additions and 52 deletions

View File

@@ -12,7 +12,7 @@ import { ForcePushMode, GitErrorCodes, Ref, RefType, Status, CommitOptions, Remo
import { Git, Stash } from './git';
import { Model } from './model';
import { Repository, Resource, ResourceGroupType } from './repository';
import { applyLineChanges, getModifiedRange, intersectDiffWithRange, invertLineChange, toLineRanges } from './staging';
import { DiffEditorSelectionHunkToolbarContext, applyLineChanges, getModifiedRange, intersectDiffWithRange, invertLineChange, toLineRanges } from './staging';
import { fromGitUri, toGitUri, isGitUri, toMergeUris, toMultiFileDiffEditorUris } from './uri';
import { dispose, grep, isDefined, isDescendant, pathEquals, relativePath } from './util';
import { GitTimelineItem } from './timelineProvider';
@@ -1511,6 +1511,30 @@ export class CommandCenter {
textEditor.selections = [new Selection(firstStagedLine, 0, firstStagedLine, 0)];
}
@command('git.diff.stageHunk')
async diffStageHunk(changes: DiffEditorSelectionHunkToolbarContext): Promise<void> {
this.diffStageHunkOrSelection(changes);
}
@command('git.diff.stageSelection')
async diffStageSelection(changes: DiffEditorSelectionHunkToolbarContext): Promise<void> {
this.diffStageHunkOrSelection(changes);
}
async diffStageHunkOrSelection(changes: DiffEditorSelectionHunkToolbarContext): Promise<void> {
const textEditor = window.activeTextEditor;
if (!textEditor) {
return;
}
const modifiedDocument = textEditor.document;
const modifiedUri = modifiedDocument.uri;
if (modifiedUri.scheme !== 'file') {
return;
}
const result = changes.originalWithModifiedChanges;
await this.runByRepository(modifiedUri, async (repository, resource) => await repository.stage(resource, result));
}
@command('git.stageSelectedRanges', { diff: true })
async stageSelectedChanges(changes: LineChange[]): Promise<void> {
const textEditor = window.activeTextEditor;

View File

@@ -142,3 +142,11 @@ export function invertLineChange(diff: LineChange): LineChange {
originalEndLineNumber: diff.modifiedEndLineNumber
};
}
export interface DiffEditorSelectionHunkToolbarContext {
mapping: unknown;
/**
* The original text with the selected modified changes applied.
*/
originalWithModifiedChanges: string;
}