6
6
import { lstat , Stats } from 'fs' ;
7
7
import * as os from 'os' ;
8
8
import * as path from 'path' ;
9
- import { commands , Disposable , LineChange , MessageOptions , OutputChannel , Position , ProgressLocation , QuickPickItem , Range , SourceControlResourceState , TextDocumentShowOptions , TextEditor , Uri , ViewColumn , window , workspace , WorkspaceEdit , WorkspaceFolder } from 'vscode' ;
9
+ import { Selection , commands , Disposable , LineChange , MessageOptions , OutputChannel , Position , ProgressLocation , QuickPickItem , Range , SourceControlResourceState , TextDocumentShowOptions , TextEditor , Uri , ViewColumn , window , workspace , WorkspaceEdit , WorkspaceFolder } from 'vscode' ;
10
10
import TelemetryReporter from 'vscode-extension-telemetry' ;
11
11
import * as nls from 'vscode-nls' ;
12
12
import { Branch , GitErrorCodes , Ref , RefType , Status } from './api/git' ;
@@ -980,7 +980,10 @@ export class CommandCenter {
980
980
return ;
981
981
}
982
982
983
- await this . _stageChanges ( textEditor , [ changes [ index ] ] ) ;
983
+ await this . _stageChanges ( textEditor , [ changes [ index ] ] ) . then ( ( ) => {
984
+ const firstStagedLine = changes [ index ] . modifiedStartLineNumber - 1 ;
985
+ textEditor . selections = [ new Selection ( firstStagedLine , 0 , firstStagedLine , 0 ) ] ;
986
+ } ) ;
984
987
}
985
988
986
989
@command ( 'git.stageSelectedRanges' , { diff : true } )
@@ -1027,7 +1030,10 @@ export class CommandCenter {
1027
1030
return ;
1028
1031
}
1029
1032
1030
- await this . _revertChanges ( textEditor , [ ...changes . slice ( 0 , index ) , ...changes . slice ( index + 1 ) ] ) ;
1033
+ await this . _revertChanges ( textEditor , [ ...changes . slice ( 0 , index ) , ...changes . slice ( index + 1 ) ] ) . then ( ( ) => {
1034
+ const firstStagedLine = changes [ index ] . modifiedStartLineNumber - 1 ;
1035
+ textEditor . selections = [ new Selection ( firstStagedLine , 0 , firstStagedLine , 0 ) ] ;
1036
+ } ) ;
1031
1037
}
1032
1038
1033
1039
@command ( 'git.revertSelectedRanges' , { diff : true } )
@@ -1049,7 +1055,10 @@ export class CommandCenter {
1049
1055
return ;
1050
1056
}
1051
1057
1052
- await this . _revertChanges ( textEditor , selectedChanges ) ;
1058
+ const selectionsBeforeRevert = textEditor . selections ;
1059
+ await this . _revertChanges ( textEditor , selectedChanges ) . then ( ( ) => {
1060
+ textEditor . selections = selectionsBeforeRevert ;
1061
+ } ) ;
1053
1062
}
1054
1063
1055
1064
private async _revertChanges ( textEditor : TextEditor , changes : LineChange [ ] ) : Promise < void > {
@@ -1062,7 +1071,6 @@ export class CommandCenter {
1062
1071
1063
1072
const originalUri = toGitUri ( modifiedUri , '~' ) ;
1064
1073
const originalDocument = await workspace . openTextDocument ( originalUri ) ;
1065
- const selectionsBeforeRevert = textEditor . selections ;
1066
1074
const visibleRangesBeforeRevert = textEditor . visibleRanges ;
1067
1075
const result = applyLineChanges ( originalDocument , modifiedDocument , changes ) ;
1068
1076
@@ -1072,7 +1080,6 @@ export class CommandCenter {
1072
1080
1073
1081
await modifiedDocument . save ( ) ;
1074
1082
1075
- textEditor . selections = selectionsBeforeRevert ;
1076
1083
textEditor . revealRange ( visibleRangesBeforeRevert [ 0 ] ) ;
1077
1084
}
1078
1085
0 commit comments