@@ -11,12 +11,13 @@ import { Registry } from 'vs/platform/registry/common/platform';
11
11
import { ICustomEditorInfo , IEditorService , IOpenEditorOverrideHandler , IOpenEditorOverrideEntry } from 'vs/workbench/services/editor/common/editorService' ;
12
12
import { IEditorInput , IEditorPane , IEditorInputFactoryRegistry , Extensions as EditorExtensions , EditorResourceAccessor } from 'vs/workbench/common/editor' ;
13
13
import { ITextEditorOptions , IEditorOptions } from 'vs/platform/editor/common/editor' ;
14
- import { IEditorGroup , OpenEditorContext } from 'vs/workbench/services/editor/common/editorGroupsService' ;
14
+ import { IEditorGroup , IEditorGroupsService , OpenEditorContext , preferredSideBySideGroupDirection } from 'vs/workbench/services/editor/common/editorGroupsService' ;
15
15
import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
16
- import { IQuickInputService , IQuickPickItem } from 'vs/platform/quickinput/common/quickInput' ;
16
+ import { IKeyMods , IQuickInputService , IQuickPickItem } from 'vs/platform/quickinput/common/quickInput' ;
17
17
import { URI } from 'vs/base/common/uri' ;
18
18
import { extname , basename , isEqual } from 'vs/base/common/resources' ;
19
19
import { Codicon } from 'vs/base/common/codicons' ;
20
+ import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
20
21
21
22
/**
22
23
* Id of the default editor for open with.
@@ -30,14 +31,17 @@ export const DEFAULT_EDITOR_ID = 'default';
30
31
* @param id Id of the editor to use. If not provided, the user is prompted for which editor to use.
31
32
*/
32
33
export async function openEditorWith (
34
+ accessor : ServicesAccessor ,
33
35
input : IEditorInput ,
34
36
id : string | undefined ,
35
37
options : IEditorOptions | ITextEditorOptions | undefined ,
36
38
group : IEditorGroup ,
37
- editorService : IEditorService ,
38
- configurationService : IConfigurationService ,
39
- quickInputService : IQuickInputService ,
40
39
) : Promise < IEditorPane | undefined > {
40
+ const editorService = accessor . get ( IEditorService ) ;
41
+ const editorGroupsService = accessor . get ( IEditorGroupsService ) ;
42
+ const configurationService = accessor . get ( IConfigurationService ) ;
43
+ const quickInputService = accessor . get ( IQuickInputService ) ;
44
+
41
45
const resource = input . resource ;
42
46
if ( ! resource ) {
43
47
return ;
@@ -77,24 +81,38 @@ export async function openEditorWith(
77
81
} ] : undefined
78
82
} ;
79
83
} ) ;
84
+ type QuickPickItem = IQuickPickItem & {
85
+ readonly handler : IOpenEditorOverrideHandler ;
86
+ } ;
80
87
81
- const picker = quickInputService . createQuickPick < ( IQuickPickItem & { handler : IOpenEditorOverrideHandler } ) > ( ) ;
88
+ const picker = quickInputService . createQuickPick < QuickPickItem > ( ) ;
82
89
picker . items = items ;
83
90
if ( items . length ) {
84
91
picker . selectedItems = [ items [ 0 ] ] ;
85
92
}
86
93
picker . placeholder = nls . localize ( 'promptOpenWith.placeHolder' , "Select editor for '{0}'" , basename ( originalResource ) ) ;
87
94
88
- const pickedItem = await new Promise < ( IQuickPickItem & { handler : IOpenEditorOverrideHandler } ) | undefined > ( resolve => {
95
+ type PickedResult = {
96
+ readonly item : QuickPickItem ;
97
+ readonly keyMods ?: IKeyMods ;
98
+ } ;
99
+
100
+ const picked = await new Promise < PickedResult | undefined > ( resolve => {
89
101
picker . onDidAccept ( ( ) => {
90
- resolve ( picker . selectedItems . length === 1 ? picker . selectedItems [ 0 ] : undefined ) ;
91
- picker . dispose ( ) ;
102
+ if ( picker . selectedItems . length === 1 ) {
103
+ resolve ( {
104
+ item : picker . selectedItems [ 0 ] ,
105
+ keyMods : picker . keyMods
106
+ } ) ;
107
+ } else {
108
+ resolve ( undefined ) ;
109
+ }
92
110
} ) ;
93
111
94
112
picker . onDidTriggerItemButton ( e => {
95
113
const pick = e . item ;
96
114
const id = pick . id ;
97
- resolve ( pick ) ; // open the view
115
+ resolve ( { item : pick } ) ; // open the view
98
116
picker . dispose ( ) ;
99
117
100
118
// And persist the setting
@@ -121,7 +139,17 @@ export async function openEditorWith(
121
139
picker . show ( ) ;
122
140
} ) ;
123
141
124
- return pickedItem ?. handler . open ( input , { ...options , override : pickedItem . id } , group , OpenEditorContext . NEW_EDITOR ) ?. override ;
142
+ if ( ! picked ) {
143
+ return undefined ;
144
+ }
145
+
146
+ const targetGroup = getTargetGroup ( group , picked . keyMods , configurationService , editorGroupsService ) ;
147
+
148
+ const openOptions : IEditorOptions = {
149
+ ...options ,
150
+ override : picked . item . id ,
151
+ } ;
152
+ return picked . item . handler . open ( input , openOptions , targetGroup , OpenEditorContext . NEW_EDITOR ) ?. override ;
125
153
}
126
154
127
155
const builtinProviderDisplayName = nls . localize ( 'builtinProviderDisplayName' , "Built-in" ) ;
@@ -132,6 +160,23 @@ export const defaultEditorOverrideEntry = Object.freeze({
132
160
detail : builtinProviderDisplayName
133
161
} ) ;
134
162
163
+ /**
164
+ * Get the group to open the editor in by looking at the pressed keys from the picker.
165
+ */
166
+ function getTargetGroup (
167
+ startingGroup : IEditorGroup ,
168
+ keyMods : IKeyMods | undefined ,
169
+ configurationService : IConfigurationService ,
170
+ editorGroupsService : IEditorGroupsService ,
171
+ ) {
172
+ if ( keyMods ?. alt || keyMods ?. ctrlCmd ) {
173
+ const direction = preferredSideBySideGroupDirection ( configurationService ) ;
174
+ const targetGroup = editorGroupsService . findGroup ( { direction } , startingGroup . id ) ;
175
+ return targetGroup ?? editorGroupsService . addGroup ( startingGroup , direction ) ;
176
+ }
177
+ return startingGroup ;
178
+ }
179
+
135
180
/**
136
181
* Get a list of all available editors, including the default text editor.
137
182
*/
0 commit comments