From 2b93c2e4e16a6e145e60d7d50506d8e561f71adf Mon Sep 17 00:00:00 2001 From: DanielArnould Date: Fri, 8 Dec 2023 08:29:26 +1100 Subject: [PATCH] Update containerBoundingRect onMouseDown Update the containerBoundingRect on every mouseDown event. This ensures the container coords are correct on page resize and hopefully fixes issue #259 . This does add some extra overhead, but less than re-rendering the whole element on a page resize. --- src/components/MouseSelection.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/components/MouseSelection.tsx b/src/components/MouseSelection.tsx index 775f9807c..68d37f288 100644 --- a/src/components/MouseSelection.tsx +++ b/src/components/MouseSelection.tsx @@ -81,9 +81,7 @@ class MouseSelection extends Component { let containerBoundingRect: DOMRect | null = null; const containerCoords = (pageX: number, pageY: number) => { - if (!containerBoundingRect) { - containerBoundingRect = container.getBoundingClientRect(); - } + containerBoundingRect ||= container.getBoundingClientRect(); return { x: pageX - containerBoundingRect.left + container.scrollLeft, @@ -120,6 +118,7 @@ class MouseSelection extends Component { } onDragStart(); + containerBoundingRect = container.getBoundingClientRect(); this.setState({ start: containerCoords(event.pageX, event.pageY),