Repository: microsoft/vscode (TypeScript)
Task: Bug Fix (2023-02-17 14:13:42+00:00)

Issue:
`activeEditorIsPinned` is not set when editor is auto-pinned by `workbench.action.moveEditorLeftInGroup`
Type: <b>Bug</b>

workbench.action.moveEditorLeftInGroup will automatically pin an editor if the editor to its left is pinned. When this happens activeEditorIsPinned is not updated and set to true. This context is only set when explicitly using workbench.action.pinEditor.

The reverse scenario has the same bug. Moving and editor to the right will unpin it if the editor to the right is unpinned. This will not set activeEditorIsPinned to false.

VS Code version: Code - Insiders 1.76.0-insider (c7930ca55d072608625ba76c13b5f9baaf9a2136, 2023-02-10T16:22:19.445Z)
OS version: Windows_NT x64 10.0.19045
Modes:
Sandboxed: Yes

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|AMD Ryzen 9 5950X 16-Core Processor             (32 x 3400)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: disabled_off<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_renderer: enabled_on<br>video_decode: enabled<br>video_encode: enabled<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: disabled_off|
|Load (avg)|undefined|
|Memory (System)|31.92GB (18.73GB free)|
|Process Argv|--crash-reporter-id 22cf4e37-a96e-4ad9-82f0-8715f8e2bf6e|
|Screen Reader|no|
|VM|0%|
</details>Extensions: none<details>
<summary>A/B Experiments</summary>

```
vsliv695:30137379
vsins829:30139715
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
pythonvspyl392:30422396
pythontb:30258533
pythonptprofiler:30281269
vsdfh931cf:30280410
vshan820:30294714
pythondataviewer:30285072
vscod805cf:30301675
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30404738
cppdebug:30492333
vsclangdf:30492506
c4g48928:30535728
dsvsc012cf:30540253
pynewext54:30618038
pylantcb52:30590116
pyindex848:30611229
nodejswelcome1:30587009
pyind779:30611226
pythonsymbol12:30651887
2i9eh265:30646982
showlangstatbar:30659908
pythonb192cf:30661257

```

</details>

<!-- generated by issue reporter -->


Discussion:
Open for help, investigation, suggested fixes, PR.

Patch:
diff --git a/src/vs/workbench/common/editor/editorGroupModel.ts b/src/vs/workbench/common/editor/editorGroupModel.ts
--- a/src/vs/workbench/common/editor/editorGroupModel.ts
+++ b/src/vs/workbench/common/editor/editorGroupModel.ts
@@ -551,6 +551,7 @@ export class EditorGroupModel extends Disposable {
 		}
 
 		const editor = this.editors[index];
+		const sticky = this.sticky;
 
 		// Adjust sticky index: editor moved out of sticky state into unsticky state
 		if (this.isSticky(index) && toIndex > this.sticky) {
@@ -566,7 +567,7 @@ export class EditorGroupModel extends Disposable {
 		this.editors.splice(index, 1);
 		this.editors.splice(toIndex, 0, editor);
 
-		// Event
+		// Move Event
 		const event: IGroupEditorMoveEvent = {
 			kind: GroupModelChangeKind.EDITOR_MOVE,
 			editor,
@@ -575,6 +576,16 @@ export class EditorGroupModel extends Disposable {
 		};
 		this._onDidModelChange.fire(event);
 
+		// Sticky Event (if sticky changed as part of the move)
+		if (sticky !== this.sticky) {
+			const event: IGroupEditorChangeEvent = {
+				kind: GroupModelChangeKind.EDITOR_STICKY,
+				editor,
+				editorIndex: toIndex
+			};
+			this._onDidModelChange.fire(event);
+		}
+
 		return editor;
 	}
 


Test patch:
diff --git a/src/vs/workbench/test/browser/parts/editor/editorGroupModel.test.ts b/src/vs/workbench/test/browser/parts/editor/editorGroupModel.test.ts
--- a/src/vs/workbench/test/browser/parts/editor/editorGroupModel.test.ts
+++ b/src/vs/workbench/test/browser/parts/editor/editorGroupModel.test.ts
@@ -2124,7 +2124,7 @@ suite('EditorGroupModel', () => {
 		assert.strictEqual(group.indexOf(input2), 1);
 		assert.strictEqual(group.indexOf(input3), 2);
 
-		group.moveEditor(input1, 2); // moved out of sticky range
+		group.moveEditor(input1, 2); // moved out of sticky range//
 		assert.strictEqual(group.isSticky(input1), false);
 		assert.strictEqual(group.isSticky(input2), true);
 		assert.strictEqual(group.isSticky(input3), false);
@@ -2171,7 +2171,7 @@ suite('EditorGroupModel', () => {
 		assert.strictEqual(group.indexOf(input2), 1);
 		assert.strictEqual(group.indexOf(input3), 2);
 
-		group.moveEditor(input3, 0); // moved into sticky range
+		group.moveEditor(input3, 0); // moved into sticky range//
 		assert.strictEqual(group.isSticky(input1), true);
 		assert.strictEqual(group.isSticky(input2), false);
 		assert.strictEqual(group.isSticky(input3), true);
@@ -2325,4 +2325,40 @@ suite('EditorGroupModel', () => {
 		assert.strictEqual(group2Events.opened[1].editor, input2group2);
 		assert.strictEqual(group2Events.opened[1].editorIndex, 1);
 	});
+
+	test('moving editor sends sticky event when sticky changes', () => {
+		const group1 = createEditorGroupModel();
+
+		const input1group1 = input();
+		const input2group1 = input();
+		const input3group1 = input();
+
+		// Open all the editors
+		group1.openEditor(input1group1, { pinned: true, active: true, index: 0, sticky: true });
+		group1.openEditor(input2group1, { pinned: true, active: false, index: 1 });
+		group1.openEditor(input3group1, { pinned: true, active: false, index: 2 });
+
+		const group1Events = groupListener(group1);
+
+		group1.moveEditor(input2group1, 0);
+		assert.strictEqual(group1Events.sticky[0].editor, input2group1);
+		assert.strictEqual(group1Events.sticky[0].editorIndex, 0);
+
+		const group2 = createEditorGroupModel();
+
+		const input1group2 = input();
+		const input2group2 = input();
+		const input3group2 = input();
+
+		// Open all the editors
+		group2.openEditor(input1group2, { pinned: true, active: true, index: 0, sticky: true });
+		group2.openEditor(input2group2, { pinned: true, active: false, index: 1 });
+		group2.openEditor(input3group2, { pinned: true, active: false, index: 2 });
+
+		const group2Events = groupListener(group2);
+
+		group2.moveEditor(input1group2, 1);
+		assert.strictEqual(group2Events.unsticky[0].editor, input1group2);
+		assert.strictEqual(group2Events.unsticky[0].editorIndex, 1);
+	});
 });