aux window - cleanup layout service (#198292)

This commit is contained in:
Benjamin Pasero
2023-11-15 13:10:40 +01:00
committed by GitHub
parent ce711aae31
commit fd80237082
8 changed files with 23 additions and 54 deletions
@@ -39,7 +39,6 @@ class EditorScopedQuickInputService extends QuickInputService {
const widget = contribution.widget;
this.host = {
_serviceBrand: undefined,
get hasContainer() { return true; },
get mainContainer() { return widget.getDomNode(); },
getContainer() { return widget.getDomNode(); },
get containers() { return [widget.getDomNode()]; },
@@ -8,7 +8,7 @@ import { Event } from 'vs/base/common/event';
import { ILayoutService, ILayoutOffsetInfo } from 'vs/platform/layout/browser/layoutService';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { coalesce } from 'vs/base/common/arrays';
import { coalesce, firstOrDefault } from 'vs/base/common/arrays';
import { mainWindow } from 'vs/base/browser/window';
class StandaloneLayoutService implements ILayoutService {
@@ -20,35 +20,8 @@ class StandaloneLayoutService implements ILayoutService {
readonly onDidChangeActiveContainer = Event.None;
readonly onDidAddContainer = Event.None;
private _dimension?: dom.IDimension;
get mainContainerDimension(): dom.IDimension {
if (!this._dimension) {
this._dimension = dom.getClientArea(mainWindow.document.body);
}
return this._dimension;
}
get activeContainerDimension() { return this.mainContainerDimension; }
readonly mainContainerOffset: ILayoutOffsetInfo = { top: 0, quickPickTop: 0 };
readonly activeContainerOffset: ILayoutOffsetInfo = { top: 0, quickPickTop: 0 };
get hasContainer(): boolean {
return false;
}
get mainContainer(): HTMLElement {
// On a page, multiple editors can be created. Therefore, there are multiple containers, not
// just a single one. Please use `activeContainer` to get the current focused code editor
// and use its container if necessary. You can also instantiate `EditorScopedLayoutService`
// which implements `ILayoutService` but is not a part of the service collection because
// it is code editor instance specific.
throw new Error(`ILayoutService.mainContainer is not available in the standalone editor!`);
}
get containers(): Iterable<HTMLElement> {
return coalesce(this._codeEditorService.listCodeEditors().map(codeEditor => codeEditor.getContainerDomNode()));
return firstOrDefault(this._codeEditorService.listCodeEditors())?.getContainerDomNode() ?? mainWindow.document.body;
}
get activeContainer(): HTMLElement {
@@ -57,6 +30,21 @@ class StandaloneLayoutService implements ILayoutService {
return activeCodeEditor?.getContainerDomNode() ?? this.mainContainer;
}
get mainContainerDimension(): dom.IDimension {
return dom.getClientArea(this.mainContainer);
}
get activeContainerDimension() {
return dom.getClientArea(this.activeContainer);
}
readonly mainContainerOffset: ILayoutOffsetInfo = { top: 0, quickPickTop: 0 };
readonly activeContainerOffset: ILayoutOffsetInfo = { top: 0, quickPickTop: 0 };
get containers(): Iterable<HTMLElement> {
return coalesce(this._codeEditorService.listCodeEditors().map(codeEditor => codeEditor.getContainerDomNode()));
}
getContainer() {
return this.activeContainer;
}
@@ -72,9 +60,6 @@ class StandaloneLayoutService implements ILayoutService {
}
export class EditorScopedLayoutService extends StandaloneLayoutService {
override get hasContainer(): boolean {
return false;
}
override get mainContainer(): HTMLElement {
return this._container;
}
@@ -55,12 +55,6 @@ export class AccessibilityService extends Disposable implements IAccessibilitySe
private initReducedMotionListeners(reduceMotionMatcher: MediaQueryList) {
if (!this._layoutService.hasContainer) {
// we can't use `ILayoutService.container` because the application
// doesn't have a single container
return;
}
this._register(addDisposableListener(reduceMotionMatcher, 'change', () => {
this._systemMotionReduced = reduceMotionMatcher.matches;
if (this._configMotionReduced === 'auto') {
@@ -65,12 +65,10 @@ export class BrowserClipboardService extends Disposable implements IClipboardSer
});
};
if (this.layoutService.hasContainer) {
this._register(Event.runAndSubscribe(this.layoutService.onDidAddContainer, ({ container, disposables }) => {
disposables.add(addDisposableListener(container, 'click', handler));
disposables.add(addDisposableListener(container, 'keydown', handler));
}, { container: this.layoutService.mainContainer, disposables: this._store }));
}
this._register(Event.runAndSubscribe(this.layoutService.onDidAddContainer, ({ container, disposables }) => {
disposables.add(addDisposableListener(container, 'click', handler));
disposables.add(addDisposableListener(container, 'keydown', handler));
}, { container: this.layoutService.mainContainer, disposables: this._store }));
}
async writeText(text: string, type?: string): Promise<void> {
@@ -21,7 +21,7 @@ export class ContextViewService extends Disposable implements IContextViewServic
) {
super();
this.container = layoutService.hasContainer ? layoutService.mainContainer : null;
this.container = layoutService.mainContainer;
this.contextView = this._register(new ContextView(this.container, ContextViewDOMPosition.ABSOLUTE));
this.layout();
@@ -41,7 +41,7 @@ export class ContextViewService extends Disposable implements IContextViewServic
this.setContainer(container, shadowRoot ? ContextViewDOMPosition.FIXED_SHADOW : ContextViewDOMPosition.FIXED);
}
} else {
if (this.layoutService.hasContainer && this.container !== this.layoutService.activeContainer) {
if (this.container !== this.layoutService.activeContainer) {
this.setContainer(this.layoutService.activeContainer, ContextViewDOMPosition.ABSOLUTE);
}
}
@@ -63,11 +63,6 @@ export interface ILayoutService {
*/
readonly activeContainerDimension: IDimension;
/**
* Does the application have a single container?
*/
readonly hasContainer: boolean;
/**
* Main container of the application.
*
-1
View File
@@ -165,7 +165,6 @@ export abstract class Layout extends Disposable implements IWorkbenchLayoutServi
//#region Properties
readonly hasContainer = true;
readonly mainContainer = document.createElement('div');
get activeContainer() { return this.getContainerFromDocument(getActiveDocument()); }
get containers(): Iterable<HTMLElement> {
@@ -594,7 +594,6 @@ export class TestLayoutService implements IWorkbenchLayoutService {
mainContainerOffset: ILayoutOffsetInfo = { top: 0, quickPickTop: 0 };
activeContainerOffset: ILayoutOffsetInfo = { top: 0, quickPickTop: 0 };
hasContainer = true;
mainContainer: HTMLElement = mainWindow.document.body;
containers = [mainWindow.document.body];
activeContainer: HTMLElement = mainWindow.document.body;