mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 01:58:53 +01:00
debt - allow to pass in disposables to createStyleSheet
This commit is contained in:
committed by
Benjamin Pasero
parent
81f9858f1d
commit
494cc43ec8
@@ -792,13 +792,17 @@ export function focusWindow(element: Node): void {
|
||||
|
||||
const globalStylesheets = new Map<HTMLStyleElement /* main stylesheet */, Set<HTMLStyleElement /* aux window clones that track the main stylesheet */>>();
|
||||
|
||||
export function createStyleSheet(container: HTMLElement = document.head, beforeAppend?: (style: HTMLStyleElement) => void): HTMLStyleElement {
|
||||
export function createStyleSheet(container: HTMLElement = document.head, beforeAppend?: (style: HTMLStyleElement) => void, disposableStore?: DisposableStore): HTMLStyleElement {
|
||||
const style = document.createElement('style');
|
||||
style.type = 'text/css';
|
||||
style.media = 'screen';
|
||||
beforeAppend?.(style);
|
||||
container.appendChild(style);
|
||||
|
||||
if (disposableStore) {
|
||||
disposableStore.add(toDisposable(() => container.removeChild(style)));
|
||||
}
|
||||
|
||||
// With <head> as container, the stylesheet becomes global and is tracked
|
||||
// to support auxiliary windows to clone the stylesheet.
|
||||
if (container === document.head) {
|
||||
@@ -807,14 +811,16 @@ export function createStyleSheet(container: HTMLElement = document.head, beforeA
|
||||
continue; // main window is already tracked
|
||||
}
|
||||
|
||||
const disposable = cloneGlobalStyleSheet(style, targetWindow);
|
||||
const cloneDisposable = cloneGlobalStyleSheet(style, targetWindow);
|
||||
disposableStore?.add(cloneDisposable);
|
||||
|
||||
event.Event.once(onDidUnregisterWindow)(unregisteredWindow => {
|
||||
disposableStore?.add(event.Event.once(onDidUnregisterWindow)(unregisteredWindow => {
|
||||
if (unregisteredWindow === targetWindow) {
|
||||
disposable.dispose();
|
||||
cloneDisposable.dispose();
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return style;
|
||||
|
||||
Reference in New Issue
Block a user