Skip to content

Commit

Permalink
Update containerBoundingRect onMouseDown
Browse files Browse the repository at this point in the history
Update the containerBoundingRect on every mouseDown event. This ensures the container coords are correct on page resize and hopefully fixes issue agentcooper#259 .

This does add some extra overhead, but less than re-rendering the whole element on a page resize.
  • Loading branch information
DanielArnould committed Dec 7, 2023
1 parent 4265e0b commit 2b93c2e
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/components/MouseSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ class MouseSelection extends Component<Props, State> {
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,
Expand Down Expand Up @@ -120,6 +118,7 @@ class MouseSelection extends Component<Props, State> {
}

onDragStart();
containerBoundingRect = container.getBoundingClientRect();

this.setState({
start: containerCoords(event.pageX, event.pageY),
Expand Down

0 comments on commit 2b93c2e

Please sign in to comment.