aux window - add layout method (#195221)

* aux window - add `layout` method

* 💄
This commit is contained in:
Benjamin Pasero 2023-10-10 10:11:55 +02:00 committed by GitHub
parent 35ec11e41c
commit 8988b0fd43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 8 deletions

View file

@ -55,7 +55,9 @@ export class EditorParts extends Disposable implements IEditorGroupsService, IEd
disposables.add(Event.once(this.lifecycleService.onDidShutdown)(() => disposables.dispose()));
editorPart.create(partContainer, { restorePreviousState: false });
disposables.add(auxiliaryWindow.onDidResize(dimension => editorPart.layout(dimension.width, dimension.height, 0, 0)));
disposables.add(auxiliaryWindow.onWillLayout(dimension => editorPart.layout(dimension.width, dimension.height, 0, 0)));
auxiliaryWindow.layout();
this._onDidAddGroup.fire(editorPart.activeGroup);

View file

@ -25,10 +25,12 @@ export interface IAuxiliaryWindowService {
export interface IAuxiliaryWindow extends IDisposable {
readonly onDidResize: Event<Dimension>;
readonly onWillLayout: Event<Dimension>;
readonly onDidClose: Event<void>;
readonly container: HTMLElement;
layout(): void;
}
type AuxiliaryWindow = Window & typeof globalThis;
@ -56,12 +58,13 @@ export class BrowserAuxiliaryWindowService implements IAuxiliaryWindowService {
const container = this.applyHTML(auxiliaryWindow, disposables);
const { onDidResize, onDidClose } = this.registerListeners(auxiliaryWindow, container, disposables);
const { onWillLayout, onDidClose } = this.registerListeners(auxiliaryWindow, container, disposables);
return {
container,
onDidResize: onDidResize.event,
onWillLayout: onWillLayout.event,
onDidClose: onDidClose.event,
layout: () => onWillLayout.fire(getClientArea(container)),
dispose: () => disposables.dispose()
};
}
@ -123,7 +126,7 @@ export class BrowserAuxiliaryWindowService implements IAuxiliaryWindowService {
return container;
}
private registerListeners(auxiliaryWindow: AuxiliaryWindow, container: HTMLElement, disposables: DisposableStore) {
private registerListeners(auxiliaryWindow: AuxiliaryWindow, container: HTMLElement, disposables: DisposableStore): { onWillLayout: Emitter<Dimension>; onDidClose: Emitter<void> } {
const onDidClose = disposables.add(new Emitter<void>());
disposables.add(addDisposableListener(auxiliaryWindow, 'unload', () => {
onDidClose.fire();
@ -134,13 +137,13 @@ export class BrowserAuxiliaryWindowService implements IAuxiliaryWindowService {
e.preventDefault();
}));
const onDidResize = disposables.add(new Emitter<Dimension>());
const onWillLayout = disposables.add(new Emitter<Dimension>());
disposables.add(addDisposableListener(auxiliaryWindow, EventType.RESIZE, () => {
const dimension = getClientArea(auxiliaryWindow.document.body);
position(container, 0, 0, 0, 0, 'relative');
size(container, dimension.width, dimension.height);
onDidResize.fire(dimension);
onWillLayout.fire(dimension);
}));
if (isWeb) {
@ -152,7 +155,7 @@ export class BrowserAuxiliaryWindowService implements IAuxiliaryWindowService {
disposables.add(addDisposableListener(auxiliaryWindow.document.body, EventType.DROP, (e: DragEvent) => EventHelper.stop(e))); // Prevent default navigation on drop
}
return { onDidResize, onDidClose };
return { onWillLayout, onDidClose };
}
protected patchMethods(auxiliaryWindow: AuxiliaryWindow): void {