Skip to content

Commit 24b3ac4

Browse files
author
Loïc Mangeonjean
committed
fix(fit-addon): call getComputedStyle on the right window element
1 parent 5f578ba commit 24b3ac4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

addons/addon-fit/src/FitAddon.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ interface ITerminalDimensions {
2323
const MINIMUM_COLS = 2;
2424
const MINIMUM_ROWS = 1;
2525

26+
function getWindow(e: Node): Window {
27+
if (e?.ownerDocument?.defaultView) {
28+
return e.ownerDocument.defaultView.window;
29+
}
30+
31+
return window;
32+
}
33+
function getComputedStyle(el: HTMLElement): CSSStyleDeclaration {
34+
return getWindow(el).getComputedStyle(el, null);
35+
}
36+
2637
export class FitAddon implements ITerminalAddon , IFitApi {
2738
private _terminal: Terminal | undefined;
2839

@@ -69,10 +80,10 @@ export class FitAddon implements ITerminalAddon , IFitApi {
6980
? 0
7081
: (this._terminal.options.overviewRuler?.width || ViewportConstants.DEFAULT_SCROLL_BAR_WIDTH));
7182

72-
const parentElementStyle = window.getComputedStyle(this._terminal.element.parentElement);
83+
const parentElementStyle = getComputedStyle(this._terminal.element.parentElement);
7384
const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));
7485
const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')));
75-
const elementStyle = window.getComputedStyle(this._terminal.element);
86+
const elementStyle = getComputedStyle(this._terminal.element);
7687
const elementPadding = {
7788
top: parseInt(elementStyle.getPropertyValue('padding-top')),
7889
bottom: parseInt(elementStyle.getPropertyValue('padding-bottom')),

0 commit comments

Comments
 (0)