Skip to content

Commit 7941835

Browse files
lramos15bpasero
andauthored
editor group model - fix index fo unstick as well (microsoft#145773) (microsoft#148563)
Co-authored-by: Benjamin Pasero <[email protected]>
1 parent 7051cd2 commit 7941835

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/vs/workbench/common/editor/editorGroupModel.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ export class EditorGroupModel extends Disposable {
567567
kind: GroupModelChangeKind.EDITOR_MOVE,
568568
editor,
569569
oldEditorIndex: index,
570-
editorIndex: toIndex,
570+
editorIndex: toIndex
571571
};
572572
this._onDidModelChange.fire(event);
573573

@@ -735,7 +735,8 @@ export class EditorGroupModel extends Disposable {
735735
this.pin(editor);
736736

737737
// Move editor to be the last sticky editor
738-
this.moveEditor(editor, this.sticky + 1);
738+
const newEditorIndex = this.sticky + 1;
739+
this.moveEditor(editor, newEditorIndex);
739740

740741
// Adjust sticky index
741742
this.sticky++;
@@ -744,7 +745,7 @@ export class EditorGroupModel extends Disposable {
744745
const event: IGroupEditorChangeEvent = {
745746
kind: GroupModelChangeKind.EDITOR_STICKY,
746747
editor,
747-
editorIndex: this.sticky
748+
editorIndex: newEditorIndex
748749
};
749750
this._onDidModelChange.fire(event);
750751
}
@@ -768,7 +769,8 @@ export class EditorGroupModel extends Disposable {
768769
}
769770

770771
// Move editor to be the first non-sticky editor
771-
this.moveEditor(editor, this.sticky);
772+
const newEditorIndex = this.sticky;
773+
this.moveEditor(editor, newEditorIndex);
772774

773775
// Adjust sticky index
774776
this.sticky--;
@@ -777,7 +779,7 @@ export class EditorGroupModel extends Disposable {
777779
const event: IGroupEditorChangeEvent = {
778780
kind: GroupModelChangeKind.EDITOR_STICKY,
779781
editor,
780-
editorIndex
782+
editorIndex: newEditorIndex
781783
};
782784
this._onDidModelChange.fire(event);
783785
}

src/vs/workbench/test/browser/parts/editor/editorGroupModel.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,6 +2232,40 @@ suite('EditorGroupModel', () => {
22322232
assert.strictEqual(group.indexOf(input4), 2);
22332233
});
22342234

2235+
test('Sticky/Unsticky Editors sends correct editor index', function () {
2236+
const group = createEditorGroupModel();
2237+
2238+
const input1 = input();
2239+
const input2 = input();
2240+
const input3 = input();
2241+
2242+
group.openEditor(input1, { pinned: true, active: true });
2243+
group.openEditor(input2, { pinned: true, active: true });
2244+
group.openEditor(input3, { pinned: false, active: true });
2245+
2246+
assert.strictEqual(group.stickyCount, 0);
2247+
2248+
const events = groupListener(group);
2249+
2250+
group.stick(input3);
2251+
2252+
assert.strictEqual(events.sticky[0].editorIndex, 0);
2253+
assert.strictEqual(group.isSticky(input3), true);
2254+
assert.strictEqual(group.stickyCount, 1);
2255+
2256+
group.stick(input2);
2257+
2258+
assert.strictEqual(events.sticky[1].editorIndex, 1);
2259+
assert.strictEqual(group.isSticky(input2), true);
2260+
assert.strictEqual(group.stickyCount, 2);
2261+
2262+
group.unstick(input3);
2263+
assert.strictEqual(events.unsticky[0].editorIndex, 1);
2264+
assert.strictEqual(group.isSticky(input3), false);
2265+
assert.strictEqual(group.isSticky(input2), true);
2266+
assert.strictEqual(group.stickyCount, 1);
2267+
});
2268+
22352269
test('onDidMoveEditor Event', () => {
22362270
const group1 = createEditorGroupModel();
22372271
const group2 = createEditorGroupModel();

0 commit comments

Comments
 (0)