From 5589b81019babf3ff21c3e3a67d63cd942187ce2 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 4 Aug 2022 21:22:28 -0700 Subject: [PATCH] Remove IStandardWindow (#157181) This was added to support old IE versions which we no longer support https://github.com/microsoft/monaco-editor/issues/26 --- src/vs/base/browser/dom.ts | 28 ++----------------- src/vs/editor/browser/editorDom.ts | 4 +-- .../contentWidgets/contentWidgets.ts | 6 ++-- 3 files changed, 7 insertions(+), 31 deletions(-) diff --git a/src/vs/base/browser/dom.ts b/src/vs/base/browser/dom.ts index 1fce5d53ada..1ff6fda0127 100644 --- a/src/vs/base/browser/dom.ts +++ b/src/vs/base/browser/dom.ts @@ -531,8 +531,8 @@ export function position(element: HTMLElement, top: number, right?: number, bott export function getDomNodePagePosition(domNode: HTMLElement): IDomNodePagePosition { const bb = domNode.getBoundingClientRect(); return { - left: bb.left + StandardWindow.scrollX, - top: bb.top + StandardWindow.scrollY, + left: bb.left + window.scrollX, + top: bb.top + window.scrollY, width: bb.width, height: bb.height }; @@ -556,30 +556,6 @@ export function getDomNodeZoomLevel(domNode: HTMLElement): number { return zoom; } -export interface IStandardWindow { - readonly scrollX: number; - readonly scrollY: number; -} - -export const StandardWindow: IStandardWindow = new class implements IStandardWindow { - get scrollX(): number { - if (typeof window.scrollX === 'number') { - // modern browsers - return window.scrollX; - } else { - return document.body.scrollLeft + document.documentElement!.scrollLeft; - } - } - - get scrollY(): number { - if (typeof window.scrollY === 'number') { - // modern browsers - return window.scrollY; - } else { - return document.body.scrollTop + document.documentElement!.scrollTop; - } - } -}; // Adapted from WinJS // Gets the width of the element, including margins. diff --git a/src/vs/editor/browser/editorDom.ts b/src/vs/editor/browser/editorDom.ts index cd36e6c200e..4cfc92f8a6e 100644 --- a/src/vs/editor/browser/editorDom.ts +++ b/src/vs/editor/browser/editorDom.ts @@ -24,7 +24,7 @@ export class PageCoordinates { ) { } public toClientCoordinates(): ClientCoordinates { - return new ClientCoordinates(this.x - dom.StandardWindow.scrollX, this.y - dom.StandardWindow.scrollY); + return new ClientCoordinates(this.x - window.scrollX, this.y - window.scrollY); } } @@ -44,7 +44,7 @@ export class ClientCoordinates { ) { } public toPageCoordinates(): PageCoordinates { - return new PageCoordinates(this.clientX + dom.StandardWindow.scrollX, this.clientY + dom.StandardWindow.scrollY); + return new PageCoordinates(this.clientX + window.scrollX, this.clientY + window.scrollY); } } diff --git a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts index 056c24f5c73..f45578d9f15 100644 --- a/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts +++ b/src/vs/editor/browser/viewParts/contentWidgets/contentWidgets.ts @@ -340,7 +340,7 @@ class Widget { const MIN_LIMIT = Math.max(0, domNodePosition.left - width); const MAX_LIMIT = Math.min(domNodePosition.left + domNodePosition.width + width, windowSize.width); - let absoluteLeft = domNodePosition.left + left - dom.StandardWindow.scrollX; + let absoluteLeft = domNodePosition.left + left - window.scrollX; if (absoluteLeft + width > MAX_LIMIT) { const delta = absoluteLeft - (MAX_LIMIT - width); @@ -362,8 +362,8 @@ class Widget { const belowTop = bottomLeft.top + this._lineHeight; const domNodePosition = dom.getDomNodePagePosition(this._viewDomNode.domNode); - const absoluteAboveTop = domNodePosition.top + aboveTop - dom.StandardWindow.scrollY; - const absoluteBelowTop = domNodePosition.top + belowTop - dom.StandardWindow.scrollY; + const absoluteAboveTop = domNodePosition.top + aboveTop - window.scrollY; + const absoluteBelowTop = domNodePosition.top + belowTop - window.scrollY; const windowSize = dom.getClientArea(document.body); const [aboveLeft, absoluteAboveLeft] = this._layoutHorizontalSegmentInPage(windowSize, domNodePosition, topLeft.left - ctx.scrollLeft + this._contentLeft, width);