-
Notifications
You must be signed in to change notification settings - Fork 28.6k
/
editorGroup.ts
828 lines (638 loc) · 21.9 KB
/
editorGroup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Event, Emitter } from 'vs/base/common/event';
import { Extensions, IEditorInputFactoryRegistry, EditorInput, IEditorIdentifier, IEditorCloseEvent, GroupIdentifier, SideBySideEditorInput, IEditorInput, EditorsOrder } from 'vs/workbench/common/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { dispose, Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { Registry } from 'vs/platform/registry/common/platform';
import { coalesce } from 'vs/base/common/arrays';
const EditorOpenPositioning = {
LEFT: 'left',
RIGHT: 'right',
FIRST: 'first',
LAST: 'last'
};
export interface EditorCloseEvent extends IEditorCloseEvent {
editor: EditorInput;
}
export interface EditorIdentifier extends IEditorIdentifier {
groupId: GroupIdentifier;
editor: EditorInput;
}
export interface IEditorOpenOptions {
pinned?: boolean;
sticky?: boolean;
active?: boolean;
index?: number;
}
export interface ISerializedEditorInput {
id: string;
value: string;
}
export interface ISerializedEditorGroup {
id: number;
editors: ISerializedEditorInput[];
mru: number[];
preview?: number;
sticky?: number;
}
export function isSerializedEditorGroup(obj?: unknown): obj is ISerializedEditorGroup {
const group = obj as ISerializedEditorGroup;
return obj && typeof obj === 'object' && Array.isArray(group.editors) && Array.isArray(group.mru);
}
export class EditorGroup extends Disposable {
private static IDS = 0;
//#region events
private readonly _onDidActivateEditor = this._register(new Emitter<EditorInput>());
readonly onDidActivateEditor = this._onDidActivateEditor.event;
private readonly _onDidOpenEditor = this._register(new Emitter<EditorInput>());
readonly onDidOpenEditor = this._onDidOpenEditor.event;
private readonly _onDidCloseEditor = this._register(new Emitter<EditorCloseEvent>());
readonly onDidCloseEditor = this._onDidCloseEditor.event;
private readonly _onDidDisposeEditor = this._register(new Emitter<EditorInput>());
readonly onDidDisposeEditor = this._onDidDisposeEditor.event;
private readonly _onDidChangeEditorDirty = this._register(new Emitter<EditorInput>());
readonly onDidChangeEditorDirty = this._onDidChangeEditorDirty.event;
private readonly _onDidChangeEditorLabel = this._register(new Emitter<EditorInput>());
readonly onDidEditorLabelChange = this._onDidChangeEditorLabel.event;
private readonly _onDidMoveEditor = this._register(new Emitter<EditorInput>());
readonly onDidMoveEditor = this._onDidMoveEditor.event;
private readonly _onDidChangeEditorPinned = this._register(new Emitter<EditorInput>());
readonly onDidChangeEditorPinned = this._onDidChangeEditorPinned.event;
private readonly _onDidChangeEditorSticky = this._register(new Emitter<EditorInput>());
readonly onDidChangeEditorSticky = this._onDidChangeEditorSticky.event;
//#endregion
private _id: GroupIdentifier;
get id(): GroupIdentifier { return this._id; }
private editors: EditorInput[] = [];
private mru: EditorInput[] = [];
private preview: EditorInput | null = null; // editor in preview state
private active: EditorInput | null = null; // editor in active state
private sticky: number = -1; // index of first editor in sticky state
private editorOpenPositioning: ('left' | 'right' | 'first' | 'last') | undefined;
private focusRecentEditorAfterClose: boolean | undefined;
constructor(
labelOrSerializedGroup: ISerializedEditorGroup | undefined,
@IInstantiationService private readonly instantiationService: IInstantiationService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
super();
if (isSerializedEditorGroup(labelOrSerializedGroup)) {
this._id = this.deserialize(labelOrSerializedGroup);
} else {
this._id = EditorGroup.IDS++;
}
this.onConfigurationUpdated();
this.registerListeners();
}
private registerListeners(): void {
this._register(this.configurationService.onDidChangeConfiguration(() => this.onConfigurationUpdated()));
}
private onConfigurationUpdated(): void {
this.editorOpenPositioning = this.configurationService.getValue('workbench.editor.openPositioning');
this.focusRecentEditorAfterClose = this.configurationService.getValue('workbench.editor.focusRecentEditorAfterClose');
if (this.configurationService.getValue('workbench.editor.showTabs') === false) {
// Disabling tabs disables sticky editors until we support
// an indication of sticky editors when tabs are disabled
this.sticky = -1;
}
}
get count(): number {
return this.editors.length;
}
get stickyCount(): number {
return this.sticky + 1;
}
getEditors(order: EditorsOrder, options?: { excludeSticky?: boolean }): EditorInput[] {
const editors = order === EditorsOrder.MOST_RECENTLY_ACTIVE ? this.mru.slice(0) : this.editors.slice(0);
if (options?.excludeSticky) {
// MRU: need to check for index on each
if (order === EditorsOrder.MOST_RECENTLY_ACTIVE) {
return editors.filter(editor => !this.isSticky(editor));
}
// Sequential: simply start after sticky index
return editors.slice(this.sticky + 1);
}
return editors;
}
getEditorByIndex(index: number): EditorInput | undefined {
return this.editors[index];
}
get activeEditor(): EditorInput | null {
return this.active;
}
isActive(editor: EditorInput): boolean {
return this.matches(this.active, editor);
}
get previewEditor(): EditorInput | null {
return this.preview;
}
openEditor(candidate: EditorInput, options?: IEditorOpenOptions): EditorInput {
const makeSticky = options?.sticky || (typeof options?.index === 'number' && this.isSticky(options.index));
const makePinned = options?.pinned || options?.sticky;
const makeActive = options?.active || !this.activeEditor || (!makePinned && this.matches(this.preview, this.activeEditor));
const existingEditorAndIndex = this.findEditor(candidate);
// New editor
if (!existingEditorAndIndex) {
const newEditor = candidate;
const indexOfActive = this.indexOf(this.active);
// Insert into specific position
let targetIndex: number;
if (options && typeof options.index === 'number') {
targetIndex = options.index;
}
// Insert to the BEGINNING
else if (this.editorOpenPositioning === EditorOpenPositioning.FIRST) {
targetIndex = 0;
// Always make sure targetIndex is after sticky editors
// unless we are explicitly told to make the editor sticky
if (!makeSticky && this.isSticky(targetIndex)) {
targetIndex = this.sticky + 1;
}
}
// Insert to the END
else if (this.editorOpenPositioning === EditorOpenPositioning.LAST) {
targetIndex = this.editors.length;
}
// Insert to LEFT or RIGHT of active editor
else {
// Insert to the LEFT of active editor
if (this.editorOpenPositioning === EditorOpenPositioning.LEFT) {
if (indexOfActive === 0 || !this.editors.length) {
targetIndex = 0; // to the left becoming first editor in list
} else {
targetIndex = indexOfActive; // to the left of active editor
}
}
// Insert to the RIGHT of active editor
else {
targetIndex = indexOfActive + 1;
}
// Always make sure targetIndex is after sticky editors
// unless we are explicitly told to make the editor sticky
if (!makeSticky && this.isSticky(targetIndex)) {
targetIndex = this.sticky + 1;
}
}
// If the editor becomes sticky, increment the sticky index and adjust
// the targetIndex to be at the end of sticky editors unless already.
if (makeSticky) {
this.sticky++;
if (!this.isSticky(targetIndex)) {
targetIndex = this.sticky;
}
}
// Insert into our list of editors if pinned or we have no preview editor
if (makePinned || !this.preview) {
this.splice(targetIndex, false, newEditor);
}
// Handle preview
if (!makePinned) {
// Replace existing preview with this editor if we have a preview
if (this.preview) {
const indexOfPreview = this.indexOf(this.preview);
if (targetIndex > indexOfPreview) {
targetIndex--; // accomodate for the fact that the preview editor closes
}
this.replaceEditor(this.preview, newEditor, targetIndex, !makeActive);
}
this.preview = newEditor;
}
// Listeners
this.registerEditorListeners(newEditor);
// Event
this._onDidOpenEditor.fire(newEditor);
// Handle active
if (makeActive) {
this.doSetActive(newEditor);
}
return newEditor;
}
// Existing editor
else {
const [existingEditor] = existingEditorAndIndex;
// Pin it
if (makePinned) {
this.doPin(existingEditor);
}
// Activate it
if (makeActive) {
this.doSetActive(existingEditor);
}
// Respect index
if (options && typeof options.index === 'number') {
this.moveEditor(existingEditor, options.index);
}
// Stick it (intentionally after the moveEditor call in case
// the editor was already moved into the sticky range)
if (makeSticky) {
this.doStick(existingEditor, this.indexOf(existingEditor));
}
return existingEditor;
}
}
private registerEditorListeners(editor: EditorInput): void {
const listeners = new DisposableStore();
// Re-emit disposal of editor input as our own event
listeners.add(Event.once(editor.onDispose)(() => {
if (this.indexOf(editor) >= 0) {
this._onDidDisposeEditor.fire(editor);
}
}));
// Re-Emit dirty state changes
listeners.add(editor.onDidChangeDirty(() => {
this._onDidChangeEditorDirty.fire(editor);
}));
// Re-Emit label changes
listeners.add(editor.onDidChangeLabel(() => {
this._onDidChangeEditorLabel.fire(editor);
}));
// Clean up dispose listeners once the editor gets closed
listeners.add(this.onDidCloseEditor(event => {
if (event.editor.matches(editor)) {
dispose(listeners);
}
}));
}
private replaceEditor(toReplace: EditorInput, replaceWith: EditorInput, replaceIndex: number, openNext = true): void {
const event = this.doCloseEditor(toReplace, openNext, true); // optimization to prevent multiple setActive() in one call
// We want to first add the new editor into our model before emitting the close event because
// firing the close event can trigger a dispose on the same editor that is now being added.
// This can lead into opening a disposed editor which is not what we want.
this.splice(replaceIndex, false, replaceWith);
if (event) {
this._onDidCloseEditor.fire(event);
}
}
closeEditor(candidate: EditorInput, openNext = true): EditorInput | undefined {
const event = this.doCloseEditor(candidate, openNext, false);
if (event) {
this._onDidCloseEditor.fire(event);
return event.editor;
}
return undefined;
}
private doCloseEditor(candidate: EditorInput, openNext: boolean, replaced: boolean): EditorCloseEvent | undefined {
const index = this.indexOf(candidate);
if (index === -1) {
return undefined; // not found
}
const editor = this.editors[index];
const sticky = this.isSticky(index);
// Active Editor closed
if (openNext && this.matches(this.active, editor)) {
// More than one editor
if (this.mru.length > 1) {
let newActive: EditorInput;
if (this.focusRecentEditorAfterClose) {
newActive = this.mru[1]; // active editor is always first in MRU, so pick second editor after as new active
} else {
if (index === this.editors.length - 1) {
newActive = this.editors[index - 1]; // last editor is closed, pick previous as new active
} else {
newActive = this.editors[index + 1]; // pick next editor as new active
}
}
this.doSetActive(newActive);
}
// One Editor
else {
this.active = null;
}
}
// Preview Editor closed
if (this.matches(this.preview, editor)) {
this.preview = null;
}
// Remove from arrays
this.splice(index, true);
// Event
return { editor, replaced, sticky, index, groupId: this.id };
}
moveEditor(candidate: EditorInput, toIndex: number): EditorInput | undefined {
// Ensure toIndex is in bounds of our model
if (toIndex >= this.editors.length) {
toIndex = this.editors.length - 1;
} else if (toIndex < 0) {
toIndex = 0;
}
const index = this.indexOf(candidate);
if (index < 0 || toIndex === index) {
return;
}
const editor = this.editors[index];
// Adjust sticky index: editor moved out of sticky state into unsticky state
if (this.isSticky(index) && toIndex > this.sticky) {
this.sticky--;
}
// ...or editor moved into sticky state from unsticky state
else if (!this.isSticky(index) && toIndex <= this.sticky) {
this.sticky++;
}
// Move
this.editors.splice(index, 1);
this.editors.splice(toIndex, 0, editor);
// Event
this._onDidMoveEditor.fire(editor);
return editor;
}
setActive(candidate: EditorInput): EditorInput | undefined {
const res = this.findEditor(candidate);
if (!res) {
return; // not found
}
const [editor] = res;
this.doSetActive(editor);
return editor;
}
private doSetActive(editor: EditorInput): void {
if (this.matches(this.active, editor)) {
return; // already active
}
this.active = editor;
// Bring to front in MRU list
const mruIndex = this.indexOf(editor, this.mru);
this.mru.splice(mruIndex, 1);
this.mru.unshift(editor);
// Event
this._onDidActivateEditor.fire(editor);
}
pin(candidate: EditorInput): EditorInput | undefined {
const res = this.findEditor(candidate);
if (!res) {
return; // not found
}
const [editor] = res;
this.doPin(editor);
return editor;
}
private doPin(editor: EditorInput): void {
if (this.isPinned(editor)) {
return; // can only pin a preview editor
}
// Convert the preview editor to be a pinned editor
this.preview = null;
// Event
this._onDidChangeEditorPinned.fire(editor);
}
unpin(candidate: EditorInput): EditorInput | undefined {
const res = this.findEditor(candidate);
if (!res) {
return; // not found
}
const [editor] = res;
this.doUnpin(editor);
return editor;
}
private doUnpin(editor: EditorInput): void {
if (!this.isPinned(editor)) {
return; // can only unpin a pinned editor
}
// Set new
const oldPreview = this.preview;
this.preview = editor;
// Event
this._onDidChangeEditorPinned.fire(editor);
// Close old preview editor if any
if (oldPreview) {
this.closeEditor(oldPreview);
}
}
isPinned(editorOrIndex: EditorInput | number): boolean {
let editor: EditorInput;
if (typeof editorOrIndex === 'number') {
editor = this.editors[editorOrIndex];
} else {
editor = editorOrIndex;
}
return !this.matches(this.preview, editor);
}
stick(candidate: EditorInput): EditorInput | undefined {
const res = this.findEditor(candidate);
if (!res) {
return; // not found
}
const [editor, index] = res;
this.doStick(editor, index);
return editor;
}
private doStick(editor: EditorInput, index: number): void {
if (this.isSticky(index)) {
return; // can only stick a non-sticky editor
}
// Pin editor
this.pin(editor);
// Move editor to be the last sticky editor
this.moveEditor(editor, this.sticky + 1);
// Adjust sticky index
this.sticky++;
// Event
this._onDidChangeEditorSticky.fire(editor);
}
unstick(candidate: EditorInput): EditorInput | undefined {
const res = this.findEditor(candidate);
if (!res) {
return; // not found
}
const [editor, index] = res;
this.doUnstick(editor, index);
return editor;
}
private doUnstick(editor: EditorInput, index: number): void {
if (!this.isSticky(index)) {
return; // can only unstick a sticky editor
}
// Move editor to be the first non-sticky editor
this.moveEditor(editor, this.sticky);
// Adjust sticky index
this.sticky--;
// Event
this._onDidChangeEditorSticky.fire(editor);
}
isSticky(candidateOrIndex: EditorInput | number): boolean {
if (this.sticky < 0) {
return false; // no sticky editor
}
let index: number;
if (typeof candidateOrIndex === 'number') {
index = candidateOrIndex;
} else {
index = this.indexOf(candidateOrIndex);
}
if (index < 0) {
return false;
}
return index <= this.sticky;
}
private splice(index: number, del: boolean, editor?: EditorInput): void {
const editorToDeleteOrReplace = this.editors[index];
// Perform on sticky index
if (del && this.isSticky(index)) {
this.sticky--;
}
// Perform on editors array
if (editor) {
this.editors.splice(index, del ? 1 : 0, editor);
} else {
this.editors.splice(index, del ? 1 : 0);
}
// Perform on MRU
{
// Add
if (!del && editor) {
if (this.mru.length === 0) {
// the list of most recent editors is empty
// so this editor can only be the most recent
this.mru.push(editor);
} else {
// we have most recent editors. as such we
// put this newly opened editor right after
// the current most recent one because it cannot
// be the most recently active one unless
// it becomes active. but it is still more
// active then any other editor in the list.
this.mru.splice(1, 0, editor);
}
}
// Remove / Replace
else {
const indexInMRU = this.indexOf(editorToDeleteOrReplace, this.mru);
// Remove
if (del && !editor) {
this.mru.splice(indexInMRU, 1); // remove from MRU
}
// Replace
else if (del && editor) {
this.mru.splice(indexInMRU, 1, editor); // replace MRU at location
}
}
}
}
indexOf(candidate: IEditorInput | null, editors = this.editors): number {
if (!candidate) {
return -1;
}
for (let i = 0; i < editors.length; i++) {
if (this.matches(editors[i], candidate)) {
return i;
}
}
return -1;
}
private findEditor(candidate: EditorInput | null): [EditorInput, number /* index */] | undefined {
const index = this.indexOf(candidate, this.editors);
if (index === -1) {
return undefined;
}
return [this.editors[index], index];
}
contains(candidate: EditorInput, options?: { supportSideBySide?: boolean, strictEquals?: boolean }): boolean {
for (const editor of this.editors) {
if (this.matches(editor, candidate, options?.strictEquals)) {
return true;
}
if (options?.supportSideBySide && editor instanceof SideBySideEditorInput) {
if (this.matches(editor.primary, candidate, options?.strictEquals) || this.matches(editor.secondary, candidate, options?.strictEquals)) {
return true;
}
}
}
return false;
}
private matches(editor: IEditorInput | null, candidate: IEditorInput | null, strictEquals?: boolean): boolean {
if (!editor || !candidate) {
return false;
}
if (strictEquals) {
return editor === candidate;
}
return editor.matches(candidate);
}
clone(): EditorGroup {
const group = this.instantiationService.createInstance(EditorGroup, undefined);
group.editors = this.editors.slice(0);
group.mru = this.mru.slice(0);
group.preview = this.preview;
group.active = this.active;
group.sticky = this.sticky;
return group;
}
serialize(): ISerializedEditorGroup {
const registry = Registry.as<IEditorInputFactoryRegistry>(Extensions.EditorInputFactories);
// Serialize all editor inputs so that we can store them.
// Editors that cannot be serialized need to be ignored
// from mru, active, preview and sticky if any.
let serializableEditors: EditorInput[] = [];
let serializedEditors: ISerializedEditorInput[] = [];
let serializablePreviewIndex: number | undefined;
let serializableSticky = this.sticky;
for (let i = 0; i < this.editors.length; i++) {
const editor = this.editors[i];
let canSerializeEditor = false;
const factory = registry.getEditorInputFactory(editor.getTypeId());
if (factory) {
const value = factory.serialize(editor);
// Editor can be serialized
if (typeof value === 'string') {
canSerializeEditor = true;
serializedEditors.push({ id: editor.getTypeId(), value });
serializableEditors.push(editor);
if (this.preview === editor) {
serializablePreviewIndex = serializableEditors.length - 1;
}
}
// Editor cannot be serialized
else {
canSerializeEditor = false;
}
}
// Adjust index of sticky editors if the editor cannot be serialized and is pinned
if (!canSerializeEditor && this.isSticky(i)) {
serializableSticky--;
}
}
const serializableMru = this.mru.map(editor => this.indexOf(editor, serializableEditors)).filter(i => i >= 0);
return {
id: this.id,
editors: serializedEditors,
mru: serializableMru,
preview: serializablePreviewIndex,
sticky: serializableSticky >= 0 ? serializableSticky : undefined
};
}
private deserialize(data: ISerializedEditorGroup): number {
const registry = Registry.as<IEditorInputFactoryRegistry>(Extensions.EditorInputFactories);
if (typeof data.id === 'number') {
this._id = data.id;
EditorGroup.IDS = Math.max(data.id + 1, EditorGroup.IDS); // make sure our ID generator is always larger
} else {
this._id = EditorGroup.IDS++; // backwards compatibility
}
this.editors = coalesce(data.editors.map((e, index) => {
let editor: EditorInput | undefined = undefined;
const factory = registry.getEditorInputFactory(e.id);
if (factory) {
editor = factory.deserialize(this.instantiationService, e.value);
if (editor) {
this.registerEditorListeners(editor);
}
}
if (!editor && typeof data.sticky === 'number' && index <= data.sticky) {
data.sticky--; // if editor cannot be deserialized but was sticky, we need to decrease sticky index
}
return editor;
}));
this.mru = coalesce(data.mru.map(i => this.editors[i]));
this.active = this.mru[0];
if (typeof data.preview === 'number') {
this.preview = this.editors[data.preview];
}
if (typeof data.sticky === 'number') {
this.sticky = data.sticky;
}
return this._id;
}
}