@@ -17,7 +17,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
1717import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService' ;
1818import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
1919import { URI } from 'vs/base/common/uri' ;
20- import { ISCMService , ISCMRepository } from 'vs/workbench/contrib/scm/common/scm' ;
20+ import { ISCMService , ISCMRepository , ISCMProvider } from 'vs/workbench/contrib/scm/common/scm' ;
2121import { ModelDecorationOptions } from 'vs/editor/common/model/textModel' ;
2222import { registerThemingParticipant , ITheme , ICssStyleCollector , themeColorFromId , IThemeService } from 'vs/platform/theme/common/themeService' ;
2323import { registerColor } from 'vs/platform/theme/common/colorRegistry' ;
@@ -37,7 +37,7 @@ import { IDiffEditorOptions, EditorOption } from 'vs/editor/common/config/editor
3737import { Action , IAction , ActionRunner } from 'vs/base/common/actions' ;
3838import { IActionBarOptions , ActionsOrientation , IActionViewItem } from 'vs/base/browser/ui/actionbar/actionbar' ;
3939import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
40- import { basename } from 'vs/base/common/resources' ;
40+ import { basename , isEqualOrParent } from 'vs/base/common/resources' ;
4141import { MenuId , IMenuService , IMenu , MenuItemAction , MenuRegistry } from 'vs/platform/actions/common/actions' ;
4242import { createAndFillInActionBarActions , ContextAwareMenuEntryActionViewItem } from 'vs/platform/actions/browser/menuEntryActionViewItem' ;
4343import { IChange , IEditorModel , ScrollType , IEditorContribution , IDiffEditorModel } from 'vs/editor/common/editorCommon' ;
@@ -951,6 +951,23 @@ function compareChanges(a: IChange, b: IChange): number {
951951 return a . originalEndLineNumber - b . originalEndLineNumber ;
952952}
953953
954+ function createProviderComparer ( uri : URI ) : ( a : ISCMProvider , b : ISCMProvider ) => number {
955+ return ( a , b ) => {
956+ const aIsParent = isEqualOrParent ( uri , a . rootUri ! ) ;
957+ const bIsParent = isEqualOrParent ( uri , b . rootUri ! ) ;
958+
959+ if ( aIsParent && bIsParent ) {
960+ return a . rootUri ! . fsPath . length - b . rootUri ! . fsPath . length ;
961+ } else if ( aIsParent ) {
962+ return - 1 ;
963+ } else if ( bIsParent ) {
964+ return 1 ;
965+ } else {
966+ return 0 ;
967+ }
968+ } ;
969+ }
970+
954971export class DirtyDiffModel extends Disposable {
955972
956973 private _originalModel : ITextModel | null = null ;
@@ -1082,13 +1099,25 @@ export class DirtyDiffModel extends Disposable {
10821099 } ) ;
10831100 }
10841101
1085- private getOriginalResource ( ) : Promise < URI | null > {
1102+ private async getOriginalResource ( ) : Promise < URI | null > {
10861103 if ( ! this . _editorModel ) {
10871104 return Promise . resolve ( null ) ;
10881105 }
10891106
10901107 const uri = this . _editorModel . uri ;
1091- return first ( this . scmService . repositories . map ( r => ( ) => r . provider . getOriginalResource ( uri ) ) ) ;
1108+ const providers = this . scmService . repositories . map ( r => r . provider ) ;
1109+ const rootedProviders = providers . filter ( p => ! ! p . rootUri ) ;
1110+
1111+ rootedProviders . sort ( createProviderComparer ( uri ) ) ;
1112+
1113+ const result = await first ( rootedProviders . map ( p => ( ) => p . getOriginalResource ( uri ) ) ) ;
1114+
1115+ if ( result ) {
1116+ return result ;
1117+ }
1118+
1119+ const nonRootedProviders = providers . filter ( p => ! p . rootUri ) ;
1120+ return first ( nonRootedProviders . map ( p => ( ) => p . getOriginalResource ( uri ) ) ) ;
10921121 }
10931122
10941123 findNextClosestChange ( lineNumber : number , inclusive = true ) : number {
0 commit comments