From 5635ce9a00d504c3f852f5f05b2bbdaf146451df Mon Sep 17 00:00:00 2001 From: Matt Bierner <12821956+mjbvz@users.noreply.github.com> Date: Mon, 20 Apr 2026 14:11:27 -0700 Subject: [PATCH] Defer EditorMouseEvent position computation The `editorPos` and `relativePos` properties cause re-layouts because they read the target's bounding client rect. Since very few listeners actually need this, I think we should try to defer these There's a chance this could cause issues if the element is moved during the handler itself but the same would happen if checking the target's dom node directly. Testing looks ok but let's see if there are any weird edge cases I missed --- src/vs/editor/browser/editorDom.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/vs/editor/browser/editorDom.ts b/src/vs/editor/browser/editorDom.ts index 5e41bb11c15..4077e9cadc5 100644 --- a/src/vs/editor/browser/editorDom.ts +++ b/src/vs/editor/browser/editorDom.ts @@ -119,21 +119,30 @@ export class EditorMouseEvent extends StandardMouseEvent { /** * Editor's coordinates relative to the whole document. */ - public readonly editorPos: EditorPagePosition; + public get editorPos(): EditorPagePosition { + this._editorPos ??= createEditorPagePosition(this._editorViewDomNode); + return this._editorPos; + } + private _editorPos: EditorPagePosition | undefined; /** * Coordinates relative to the (top;left) of the editor. * *NOTE*: These coordinates are preferred because they take into account transformations applied to the editor. * *NOTE*: These coordinates could be negative if the mouse position is outside the editor. - */ - public readonly relativePos: CoordinatesRelativeToEditor; + */ + public get relativePos(): CoordinatesRelativeToEditor { + this._relativePos ??= createCoordinatesRelativeToEditor(this._editorViewDomNode, this.editorPos, this.pos); + return this._relativePos; + } + private _relativePos: CoordinatesRelativeToEditor | undefined; + + private readonly _editorViewDomNode: HTMLElement; constructor(e: MouseEvent, isFromPointerCapture: boolean, editorViewDomNode: HTMLElement) { super(dom.getWindow(editorViewDomNode), e); this.isFromPointerCapture = isFromPointerCapture; this.pos = new PageCoordinates(this.posx, this.posy); - this.editorPos = createEditorPagePosition(editorViewDomNode); - this.relativePos = createCoordinatesRelativeToEditor(editorViewDomNode, this.editorPos, this.pos); + this._editorViewDomNode = editorViewDomNode; } }