mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 10:38:59 +01:00
Implements #206808
This commit is contained in:
committed by
Henning Dieterichs
parent
15715aedf0
commit
b7d35c8bdd
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user