@@ -8,7 +8,7 @@ import { EditorActivation, EditorOverride, IResourceEditorInput } from 'vs/platf
8
8
import { URI } from 'vs/base/common/uri' ;
9
9
import { Event } from 'vs/base/common/event' ;
10
10
import { DEFAULT_EDITOR_ASSOCIATION , EditorsOrder , GroupIdentifier , IEditorInputWithOptions , IEditorPane , IResourceDiffEditorInput , isEditorInputWithOptions , isResourceDiffEditorInput , isUntitledResourceEditorInput , IUntitledTextResourceEditorInput , IUntypedEditorInput , UntypedEditorContext } from 'vs/workbench/common/editor' ;
11
- import { workbenchInstantiationService , TestServiceAccessor , registerTestEditor , TestFileEditorInput , ITestInstantiationService , registerTestResourceEditor , registerTestSideBySideEditor , createEditorPart , registerTestFileEditor } from 'vs/workbench/test/browser/workbenchTestServices' ;
11
+ import { workbenchInstantiationService , TestServiceAccessor , registerTestEditor , TestFileEditorInput , ITestInstantiationService , registerTestResourceEditor , registerTestSideBySideEditor , createEditorPart , registerTestFileEditor , TestEditorWithOptions , TestTextFileEditor } from 'vs/workbench/test/browser/workbenchTestServices' ;
12
12
import { TextResourceEditorInput } from 'vs/workbench/common/editor/textResourceEditorInput' ;
13
13
import { EditorService } from 'vs/workbench/services/editor/browser/editorService' ;
14
14
import { IEditorGroup , IEditorGroupsService , GroupDirection , GroupsArrangement } from 'vs/workbench/services/editor/common/editorGroupsService' ;
@@ -71,7 +71,7 @@ suite('EditorService', () => {
71
71
return [ part , editorService , instantiationService . createInstance ( TestServiceAccessor ) ] ;
72
72
}
73
73
74
- test ( 'openEditor ' , async ( ) => {
74
+ test ( 'basics ' , async ( ) => {
75
75
const [ , service ] = await createEditorService ( ) ;
76
76
77
77
let input = new TestFileEditorInput ( URI . parse ( 'my://resource-basics' ) , TEST_EDITOR_INPUT_ID ) ;
@@ -178,11 +178,11 @@ suite('EditorService', () => {
178
178
didCloseEditorListener . dispose ( ) ;
179
179
} ) ;
180
180
181
- test ( 'openEditor - override handling ' , ( ) => {
181
+ test ( 'openEditor() ' , ( ) => {
182
182
return testOpenEditors ( false ) ;
183
183
} ) ;
184
184
185
- test ( 'openEditors - override handling ' , ( ) => {
185
+ test ( 'openEditors() ' , ( ) => {
186
186
return testOpenEditors ( true ) ;
187
187
} ) ;
188
188
@@ -265,10 +265,11 @@ suite('EditorService', () => {
265
265
{
266
266
let untypedEditor : IResourceEditorInput = { resource : URI . file ( 'file.editor-service-override-tests' ) } ;
267
267
let pane = await openEditor ( untypedEditor ) ;
268
+ let typedEditor = pane ?. input ;
268
269
269
270
assert . strictEqual ( pane ?. group , rootGroup ) ;
270
- assert . ok ( pane . input instanceof TestFileEditorInput ) ;
271
- assert . strictEqual ( pane . input . resource . toString ( ) , untypedEditor . resource . toString ( ) ) ;
271
+ assert . ok ( typedEditor instanceof TestFileEditorInput ) ;
272
+ assert . strictEqual ( typedEditor . resource . toString ( ) , untypedEditor . resource . toString ( ) ) ;
272
273
273
274
assert . strictEqual ( editorFactoryCalled , 1 ) ;
274
275
assert . strictEqual ( untitledEditorFactoryCalled , 0 ) ;
@@ -278,17 +279,43 @@ suite('EditorService', () => {
278
279
assert . ok ( ! lastUntitledEditorFactoryEditor ) ;
279
280
assert . ok ( ! lastDiffEditorFactoryEditor ) ;
280
281
282
+ // opening the same editor should not create
283
+ // a new editor input
284
+ pane = await openEditor ( untypedEditor ) ;
285
+ assert . strictEqual ( pane ?. input , typedEditor ) ;
286
+
287
+ // replaceEditors should work too
288
+ let untypedEditorReplacement : IResourceEditorInput = { resource : URI . file ( 'file-replaced.editor-service-override-tests' ) } ;
289
+ await service . replaceEditors ( [ {
290
+ editor : typedEditor ,
291
+ replacement : untypedEditorReplacement
292
+ } ] , rootGroup ) ;
293
+
294
+ typedEditor = rootGroup . activeEditor ! ;
295
+
296
+ assert . ok ( typedEditor instanceof TestFileEditorInput ) ;
297
+ assert . strictEqual ( typedEditor . resource . toString ( ) , untypedEditorReplacement . resource . toString ( ) ) ;
298
+
299
+ assert . strictEqual ( editorFactoryCalled , 3 ) ;
300
+ assert . strictEqual ( untitledEditorFactoryCalled , 0 ) ;
301
+ assert . strictEqual ( diffEditorFactoryCalled , 0 ) ;
302
+
303
+ assert . strictEqual ( lastEditorFactoryEditor , untypedEditorReplacement ) ;
304
+ assert . ok ( ! lastUntitledEditorFactoryEditor ) ;
305
+ assert . ok ( ! lastDiffEditorFactoryEditor ) ;
306
+
281
307
await resetTestState ( ) ;
282
308
}
283
309
284
310
// untyped resource editor, options (override disabled), no group
285
311
{
286
312
let untypedEditor : IResourceEditorInput = { resource : URI . file ( 'file.editor-service-override-tests' ) , options : { override : EditorOverride . DISABLED } } ;
287
313
let pane = await openEditor ( untypedEditor ) ;
314
+ let typedEditor = pane ?. input ;
288
315
289
316
assert . strictEqual ( pane ?. group , rootGroup ) ;
290
- assert . ok ( pane . input instanceof FileEditorInput ) ;
291
- assert . strictEqual ( pane . input . resource . toString ( ) , untypedEditor . resource . toString ( ) ) ;
317
+ assert . ok ( typedEditor instanceof FileEditorInput ) ;
318
+ assert . strictEqual ( typedEditor . resource . toString ( ) , untypedEditor . resource . toString ( ) ) ;
292
319
293
320
assert . strictEqual ( editorFactoryCalled , 0 ) ;
294
321
assert . strictEqual ( untitledEditorFactoryCalled , 0 ) ;
@@ -298,6 +325,11 @@ suite('EditorService', () => {
298
325
assert . ok ( ! lastUntitledEditorFactoryEditor ) ;
299
326
assert . ok ( ! lastDiffEditorFactoryEditor ) ;
300
327
328
+ // opening the same editor should not create
329
+ // a new editor input
330
+ pane = await openEditor ( untypedEditor ) ;
331
+ assert . strictEqual ( pane ?. input , typedEditor ) ;
332
+
301
333
await resetTestState ( ) ;
302
334
}
303
335
@@ -458,10 +490,11 @@ suite('EditorService', () => {
458
490
{
459
491
let typedEditor = new TestFileEditorInput ( URI . file ( 'file.editor-service-override-tests' ) , TEST_EDITOR_INPUT_ID ) ;
460
492
let pane = await openEditor ( { editor : typedEditor } ) ;
493
+ let typedInput = pane ?. input ;
461
494
462
495
assert . strictEqual ( pane ?. group , rootGroup ) ;
463
- assert . ok ( pane . input instanceof TestFileEditorInput ) ;
464
- assert . strictEqual ( pane . input . resource . toString ( ) , typedEditor . resource . toString ( ) ) ;
496
+ assert . ok ( typedInput instanceof TestFileEditorInput ) ;
497
+ assert . strictEqual ( typedInput . resource . toString ( ) , typedEditor . resource . toString ( ) ) ;
465
498
466
499
assert . strictEqual ( editorFactoryCalled , 1 ) ;
467
500
assert . strictEqual ( untitledEditorFactoryCalled , 0 ) ;
@@ -471,17 +504,43 @@ suite('EditorService', () => {
471
504
assert . ok ( ! lastUntitledEditorFactoryEditor ) ;
472
505
assert . ok ( ! lastDiffEditorFactoryEditor ) ;
473
506
507
+ // opening the same editor should not create
508
+ // a new editor input
509
+ pane = await openEditor ( typedEditor ) ;
510
+ assert . strictEqual ( pane ?. input , typedInput ) ;
511
+
512
+ // replaceEditors should work too
513
+ let typedEditorReplacement = new TestFileEditorInput ( URI . file ( 'file-replaced.editor-service-override-tests' ) , TEST_EDITOR_INPUT_ID ) ;
514
+ await service . replaceEditors ( [ {
515
+ editor : typedEditor ,
516
+ replacement : typedEditorReplacement
517
+ } ] , rootGroup ) ;
518
+
519
+ typedInput = rootGroup . activeEditor ! ;
520
+
521
+ assert . ok ( typedInput instanceof TestFileEditorInput ) ;
522
+ assert . strictEqual ( typedInput . resource . toString ( ) , typedEditorReplacement . resource . toString ( ) ) ;
523
+
524
+ assert . strictEqual ( editorFactoryCalled , 3 ) ;
525
+ assert . strictEqual ( untitledEditorFactoryCalled , 0 ) ;
526
+ assert . strictEqual ( diffEditorFactoryCalled , 0 ) ;
527
+
528
+ assert . strictEqual ( ( lastEditorFactoryEditor as IResourceEditorInput ) . resource . toString ( ) , typedInput . resource . toString ( ) ) ;
529
+ assert . ok ( ! lastUntitledEditorFactoryEditor ) ;
530
+ assert . ok ( ! lastDiffEditorFactoryEditor ) ;
531
+
474
532
await resetTestState ( ) ;
475
533
}
476
534
477
535
// typed editor, options (override disabled), no group
478
536
{
479
537
let typedEditor = new TestFileEditorInput ( URI . file ( 'file.editor-service-override-tests' ) , TEST_EDITOR_INPUT_ID ) ;
480
538
let pane = await openEditor ( { editor : typedEditor , options : { override : EditorOverride . DISABLED } } ) ;
539
+ let typedInput = pane ?. input ;
481
540
482
541
assert . strictEqual ( pane ?. group , rootGroup ) ;
483
- assert . ok ( pane . input instanceof TestFileEditorInput ) ;
484
- assert . strictEqual ( pane . input . resource . toString ( ) , typedEditor . resource . toString ( ) ) ;
542
+ assert . ok ( typedInput instanceof TestFileEditorInput ) ;
543
+ assert . strictEqual ( typedInput . resource . toString ( ) , typedEditor . resource . toString ( ) ) ;
485
544
486
545
assert . strictEqual ( editorFactoryCalled , 0 ) ;
487
546
assert . strictEqual ( untitledEditorFactoryCalled , 0 ) ;
@@ -491,6 +550,11 @@ suite('EditorService', () => {
491
550
assert . ok ( ! lastUntitledEditorFactoryEditor ) ;
492
551
assert . ok ( ! lastDiffEditorFactoryEditor ) ;
493
552
553
+ // opening the same editor should not create
554
+ // a new editor input
555
+ pane = await openEditor ( typedEditor ) ;
556
+ assert . strictEqual ( pane ?. input , typedInput ) ;
557
+
494
558
await resetTestState ( ) ;
495
559
}
496
560
@@ -692,10 +756,11 @@ suite('EditorService', () => {
692
756
{
693
757
let untypedEditor : IUntitledTextResourceEditorInput = { resource : URI . file ( 'file-original.editor-service-override-tests' ) . with ( { scheme : 'untitled' } ) } ;
694
758
let pane = await openEditor ( untypedEditor ) ;
759
+ let typedEditor = pane ?. input ;
695
760
696
761
assert . strictEqual ( pane ?. group , rootGroup ) ;
697
- assert . ok ( pane . input instanceof TestFileEditorInput ) ;
698
- assert . strictEqual ( pane . input . resource . scheme , 'untitled' ) ;
762
+ assert . ok ( typedEditor instanceof TestFileEditorInput ) ;
763
+ assert . strictEqual ( typedEditor . resource . scheme , 'untitled' ) ;
699
764
700
765
assert . strictEqual ( editorFactoryCalled , 0 ) ;
701
766
assert . strictEqual ( untitledEditorFactoryCalled , 1 ) ;
@@ -705,6 +770,11 @@ suite('EditorService', () => {
705
770
assert . strictEqual ( lastUntitledEditorFactoryEditor , untypedEditor ) ;
706
771
assert . ok ( ! lastDiffEditorFactoryEditor ) ;
707
772
773
+ // opening the same editor should not create
774
+ // a new editor input
775
+ pane = await openEditor ( untypedEditor ) ;
776
+ assert . strictEqual ( pane ?. input , typedEditor ) ;
777
+
708
778
await resetTestState ( ) ;
709
779
}
710
780
@@ -736,11 +806,16 @@ suite('EditorService', () => {
736
806
{
737
807
// untyped diff editor, no options, no group
738
808
{
739
- let untypedEditor : IResourceDiffEditorInput = { originalInput : { resource : URI . file ( 'file-original.editor-service-override-tests' ) } , modifiedInput : { resource : URI . file ( 'file-modified.editor-service-override-tests' ) } , options : { override : 'editorServiceOverrideTests' } } ;
809
+ let untypedEditor : IResourceDiffEditorInput = {
810
+ originalInput : { resource : URI . file ( 'file-original.editor-service-override-tests' ) } ,
811
+ modifiedInput : { resource : URI . file ( 'file-modified.editor-service-override-tests' ) } ,
812
+ options : { override : 'editorServiceOverrideTests' }
813
+ } ;
740
814
let pane = await openEditor ( untypedEditor ) ;
815
+ let typedEditor = pane ?. input ;
741
816
742
817
assert . strictEqual ( pane ?. group , rootGroup ) ;
743
- assert . ok ( pane . input instanceof TestFileEditorInput ) ;
818
+ assert . ok ( typedEditor instanceof TestFileEditorInput ) ;
744
819
745
820
assert . strictEqual ( editorFactoryCalled , 0 ) ;
746
821
assert . strictEqual ( untitledEditorFactoryCalled , 0 ) ;
@@ -755,7 +830,11 @@ suite('EditorService', () => {
755
830
756
831
// untyped diff editor, no options, SIDE_GROUP
757
832
{
758
- let untypedEditor : IResourceDiffEditorInput = { originalInput : { resource : URI . file ( 'file-original.editor-service-override-tests' ) } , modifiedInput : { resource : URI . file ( 'file-modified.editor-service-override-tests' ) } , options : { override : 'editorServiceOverrideTests' } } ;
833
+ let untypedEditor : IResourceDiffEditorInput = {
834
+ originalInput : { resource : URI . file ( 'file-original.editor-service-override-tests' ) } ,
835
+ modifiedInput : { resource : URI . file ( 'file-modified.editor-service-override-tests' ) } ,
836
+ options : { override : 'editorServiceOverrideTests' }
837
+ } ;
759
838
let pane = await openEditor ( untypedEditor , SIDE_GROUP ) ;
760
839
761
840
assert . strictEqual ( accessor . editorGroupService . groups . length , 2 ) ;
@@ -893,8 +972,66 @@ suite('EditorService', () => {
893
972
await resetTestState ( ) ;
894
973
}
895
974
}
975
+
976
+ // openEditors with >1 editor
977
+ if ( useOpenEditors ) {
978
+
979
+ // mix of untyped and typed editors
980
+ {
981
+ let untypedEditor1 : IResourceEditorInput = { resource : URI . file ( 'file1.editor-service-override-tests' ) } ;
982
+ let untypedEditor2 : IResourceEditorInput = { resource : URI . file ( 'file2.editor-service-override-tests' ) , options : { override : EditorOverride . DISABLED } } ;
983
+ let untypedEditor3 : IEditorInputWithOptions = { editor : new TestFileEditorInput ( URI . file ( 'file3.editor-service-override-tests' ) , TEST_EDITOR_INPUT_ID ) } ;
984
+ let untypedEditor4 : IEditorInputWithOptions = { editor : new TestFileEditorInput ( URI . file ( 'file4.editor-service-override-tests' ) , TEST_EDITOR_INPUT_ID ) , options : { override : EditorOverride . DISABLED } } ;
985
+ let untypedEditor5 : IResourceEditorInput = { resource : URI . file ( 'file5.editor-service-override-tests' ) } ;
986
+ let pane = ( await service . openEditors ( [ untypedEditor1 , untypedEditor2 , untypedEditor3 , untypedEditor4 , untypedEditor5 ] ) ) [ 0 ] ;
987
+
988
+ assert . strictEqual ( pane ?. group , rootGroup ) ;
989
+ assert . strictEqual ( pane ?. group . count , 5 ) ;
990
+
991
+ assert . strictEqual ( editorFactoryCalled , 3 ) ;
992
+ assert . strictEqual ( untitledEditorFactoryCalled , 0 ) ;
993
+ assert . strictEqual ( diffEditorFactoryCalled , 0 ) ;
994
+
995
+ assert . ok ( lastEditorFactoryEditor ) ;
996
+ assert . ok ( ! lastUntitledEditorFactoryEditor ) ;
997
+ assert . ok ( ! lastDiffEditorFactoryEditor ) ;
998
+
999
+ await resetTestState ( ) ;
1000
+ }
1001
+ }
896
1002
}
897
1003
1004
+ test ( 'openEditor() applies options if editor already opened' , async ( ) => {
1005
+ disposables . add ( registerTestFileEditor ( ) ) ;
1006
+
1007
+ const [ , service , accessor ] = await createEditorService ( ) ;
1008
+
1009
+ disposables . add ( accessor . editorOverrideService . registerEditor (
1010
+ '*.editor-service-override-tests' ,
1011
+ { id : 'editorServiceOverrideTests' , label : 'Label' , priority : RegisteredEditorPriority . exclusive } ,
1012
+ { } ,
1013
+ editor => ( { editor : new TestFileEditorInput ( editor . resource , 'editorServiceOverrideTests' ) } )
1014
+ ) ) ;
1015
+
1016
+ // Typed editor
1017
+ let pane = await service . openEditor ( new TestFileEditorInput ( URI . parse ( 'my://resource-openEditors' ) , 'editorServiceOverrideTests' ) ) ;
1018
+ pane = await service . openEditor ( new TestFileEditorInput ( URI . parse ( 'my://resource-openEditors' ) , 'editorServiceOverrideTests' ) , { sticky : true , preserveFocus : true } ) ;
1019
+
1020
+ assert . ok ( pane instanceof TestEditorWithOptions ) ;
1021
+ assert . strictEqual ( pane . lastSetOptions ?. sticky , true ) ;
1022
+ assert . strictEqual ( pane . lastSetOptions ?. preserveFocus , true ) ;
1023
+
1024
+ await pane . group ?. closeAllEditors ( ) ;
1025
+
1026
+ // Untyped editor (without registered editor)
1027
+ pane = await service . openEditor ( { resource : URI . file ( 'resource-openEditors' ) } ) ;
1028
+ pane = await service . openEditor ( { resource : URI . file ( 'resource-openEditors' ) , options : { sticky : true , preserveFocus : true } } ) ;
1029
+
1030
+ assert . ok ( pane instanceof TestTextFileEditor ) ;
1031
+ assert . strictEqual ( pane . lastSetOptions ?. sticky , true ) ;
1032
+ assert . strictEqual ( pane . lastSetOptions ?. preserveFocus , true ) ;
1033
+ } ) ;
1034
+
898
1035
test ( 'isOpen() with side by side editor' , async ( ) => {
899
1036
const [ part , service ] = await createEditorService ( ) ;
900
1037
0 commit comments