Skip to content

Commit 35b8096

Browse files
authored
clicking on the window, group entry should reveal /focus that window (fix microsoft#196456) (microsoft#196615)
* clicking on the window, group entry should reveal /focus that window (fix microsoft#196456) * 💄
1 parent e685838 commit 35b8096

File tree

5 files changed

+32
-25
lines changed

5 files changed

+32
-25
lines changed

src/vs/workbench/browser/parts/editor/editorPart.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { localize } from 'vs/nls';
77
import { IThemeService } from 'vs/platform/theme/common/themeService';
88
import { Part } from 'vs/workbench/browser/part';
9-
import { Dimension, isAncestor, $, EventHelper, addDisposableGenericMouseDownListener } from 'vs/base/browser/dom';
9+
import { Dimension, isAncestor, $, EventHelper, addDisposableGenericMouseDownListener, getWindow } from 'vs/base/browser/dom';
1010
import { Event, Emitter, Relay } from 'vs/base/common/event';
1111
import { contrastBorder, editorBackground } from 'vs/platform/theme/common/colorRegistry';
1212
import { GroupDirection, GroupsArrangement, GroupOrientation, IMergeGroupOptions, MergeGroupMode, GroupsOrder, GroupLocation, IFindGroupScope, EditorGroupLayout, GroupLayoutArgument, IEditorSideGroup, IEditorDropTargetDelegate, IAuxiliaryEditorPart, IEditorPart } from 'vs/workbench/services/editor/common/editorGroupsService';
@@ -32,6 +32,7 @@ import { DeferredPromise, Promises } from 'vs/base/common/async';
3232
import { findGroup } from 'vs/workbench/services/editor/common/editorGroupFinder';
3333
import { SIDE_GROUP } from 'vs/workbench/services/editor/common/editorService';
3434
import { IBoundarySashes } from 'vs/base/browser/ui/sash/sash';
35+
import { IHostService } from 'vs/workbench/services/host/browser/host';
3536

3637
interface IEditorPartUIState {
3738
readonly serializedGrid: ISerializedGrid;
@@ -152,6 +153,7 @@ export class EditorPart extends Part implements IEditorPart {
152153
@IConfigurationService private readonly configurationService: IConfigurationService,
153154
@IStorageService storageService: IStorageService,
154155
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService,
156+
@IHostService private readonly hostService: IHostService
155157
) {
156158
super(id, { hasTitle: false }, themeService, storageService, layoutService);
157159

@@ -660,6 +662,10 @@ export class EditorPart extends Part implements IEditorPart {
660662
}
661663

662664
private doSetGroupActive(group: IEditorGroupView): void {
665+
666+
// Ensure window on top
667+
this.hostService.moveTop(getWindow(this.element));
668+
663669
if (this._activeGroup !== group) {
664670
const previousActiveGroup = this._activeGroup;
665671
this._activeGroup = group;
@@ -1315,9 +1321,10 @@ export class MainEditorPart extends EditorPart {
13151321
@IThemeService themeService: IThemeService,
13161322
@IConfigurationService configurationService: IConfigurationService,
13171323
@IStorageService storageService: IStorageService,
1318-
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService
1324+
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService,
1325+
@IHostService hostService: IHostService
13191326
) {
1320-
super(editorPartsView, Parts.EDITOR_PART, '', instantiationService, themeService, configurationService, storageService, layoutService);
1327+
super(editorPartsView, Parts.EDITOR_PART, '', instantiationService, themeService, configurationService, storageService, layoutService, hostService);
13211328
}
13221329
}
13231330

@@ -1334,10 +1341,11 @@ export class AuxiliaryEditorPart extends EditorPart implements IAuxiliaryEditorP
13341341
@IThemeService themeService: IThemeService,
13351342
@IConfigurationService configurationService: IConfigurationService,
13361343
@IStorageService storageService: IStorageService,
1337-
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService
1344+
@IWorkbenchLayoutService layoutService: IWorkbenchLayoutService,
1345+
@IHostService hostService: IHostService
13381346
) {
13391347
const id = AuxiliaryEditorPart.COUNTER++;
1340-
super(editorPartsView, `workbench.parts.auxiliaryEditor.${id}`, localize('auxiliaryEditorPartLabel', "Window {0}", id + 1), instantiationService, themeService, configurationService, storageService, layoutService);
1348+
super(editorPartsView, `workbench.parts.auxiliaryEditor.${id}`, localize('auxiliaryEditorPartLabel', "Window {0}", id + 1), instantiationService, themeService, configurationService, storageService, layoutService, hostService);
13411349
}
13421350

13431351
protected override saveState(): void {

src/vs/workbench/contrib/files/browser/views/openEditorsView.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ export class OpenEditorsView extends ViewPane {
286286
this.openEditor(e.element, { preserveFocus: e.editorOptions.preserveFocus, pinned: e.editorOptions.pinned, sideBySide: e.sideBySide });
287287
} else {
288288
this.editorGroupService.activateGroup(e.element);
289+
if (!e.editorOptions.preserveFocus) {
290+
e.element.focus();
291+
}
289292
}
290293
}));
291294

src/vs/workbench/electron-sandbox/window.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { localize } from 'vs/nls';
77
import { URI } from 'vs/base/common/uri';
88
import { onUnexpectedError } from 'vs/base/common/errors';
99
import { equals } from 'vs/base/common/objects';
10-
import { EventType, EventHelper, addDisposableListener, ModifierKeyEmitter, getActiveElement } from 'vs/base/browser/dom';
10+
import { EventType, EventHelper, addDisposableListener, ModifierKeyEmitter, getActiveElement, getActiveWindow } from 'vs/base/browser/dom';
1111
import { Separator, WorkbenchActionExecutedClassification, WorkbenchActionExecutedEvent } from 'vs/base/common/actions';
1212
import { IFileService } from 'vs/platform/files/common/files';
1313
import { EditorResourceAccessor, IUntitledTextResourceEditorInput, SideBySideEditor, pathsToEditors, IResourceDiffEditorInput, IUntypedEditorInput, IEditorPane, isResourceEditorInput, IResourceMergeEditorInput } from 'vs/workbench/common/editor';
@@ -680,6 +680,10 @@ export class NativeWindow extends Disposable {
680680
const that = this;
681681
const originalWindowFocus = window.focus.bind(window);
682682
window.focus = async function () {
683+
if (getActiveWindow() === window) {
684+
return;
685+
}
686+
683687
originalWindowFocus();
684688

685689
await that.nativeHostService.focusWindow();

src/vs/workbench/services/auxiliaryWindow/electron-sandbox/auxiliaryWindowService.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
1313
import { INativeHostService } from 'vs/platform/native/common/native';
1414
import { DeferredPromise } from 'vs/base/common/async';
1515
import { IDialogService } from 'vs/platform/dialogs/common/dialogs';
16+
import { getActiveWindow } from 'vs/base/browser/dom';
1617

1718
type AuxiliaryWindow = BaseAuxiliaryWindow & {
1819
readonly vscodeWindowId: Promise<number>;
19-
20-
moveTop: () => void;
2120
};
2221

2322
export function isAuxiliaryWindow(obj: unknown): obj is AuxiliaryWindow {
2423
const candidate = obj as AuxiliaryWindow | undefined;
2524

26-
return candidate?.vscodeWindowId instanceof Promise && typeof candidate?.moveTop === 'function';
25+
return candidate?.vscodeWindowId instanceof Promise;
2726
}
2827

2928
export class NativeAuxiliaryWindowService extends BrowserAuxiliaryWindowService {
@@ -70,20 +69,14 @@ export class NativeAuxiliaryWindowService extends BrowserAuxiliaryWindowService
7069
const that = this;
7170
const originalWindowFocus = auxiliaryWindow.focus.bind(auxiliaryWindow);
7271
auxiliaryWindow.focus = async function () {
72+
if (getActiveWindow() === auxiliaryWindow) {
73+
return;
74+
}
75+
7376
originalWindowFocus();
7477

7578
await that.nativeHostService.focusWindow({ targetWindowId: await windowId.p });
7679
};
77-
78-
// Add a method to move window to the top
79-
Object.defineProperty(auxiliaryWindow, 'moveTop', {
80-
value: async () => {
81-
await that.nativeHostService.moveWindowTop({ targetWindowId: await windowId.p });
82-
},
83-
writable: false,
84-
enumerable: false,
85-
configurable: false
86-
});
8780
}
8881
}
8982

src/vs/workbench/services/host/electron-sandbox/nativeHostService.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { NativeHostService } from 'vs/platform/native/electron-sandbox/nativeHos
1515
import { INativeWorkbenchEnvironmentService } from 'vs/workbench/services/environment/electron-sandbox/environmentService';
1616
import { IMainProcessService } from 'vs/platform/ipc/common/mainProcessService';
1717
import { isAuxiliaryWindow } from 'vs/workbench/services/auxiliaryWindow/electron-sandbox/auxiliaryWindowService';
18+
import { getActiveWindow } from 'vs/base/browser/dom';
1819

1920
class WorkbenchNativeHostService extends NativeHostService {
2021

@@ -115,14 +116,12 @@ class WorkbenchHostService extends Disposable implements IHostService {
115116
return this.nativeHostService.toggleFullScreen();
116117
}
117118

118-
async moveTop(win: Window & typeof globalThis): Promise<void> {
119-
if (win === window) {
120-
return this.nativeHostService.moveWindowTop();
119+
async moveTop(window: Window & typeof globalThis): Promise<void> {
120+
if (getActiveWindow() === window) {
121+
return;
121122
}
122123

123-
if (isAuxiliaryWindow(win)) {
124-
return win.moveTop();
125-
}
124+
return this.nativeHostService.moveWindowTop(isAuxiliaryWindow(window) ? { targetWindowId: await window.vscodeWindowId } : undefined);
126125
}
127126

128127
//#endregion

0 commit comments

Comments
 (0)