agentcooper / react-pdf-highlighter

Set of React components for PDF annotation
https://agentcooper.github.io/react-pdf-highlighter/
MIT License
1.04k stars 407 forks source link

Fix mouse selection on resize #260

Closed DanielArnould closed 7 months ago

DanielArnould commented 9 months ago

This is just a simple fix for issue #259 . Before, the containerBounderRect in MouseSelection was only being set whenever containerCoords was first called. Since MouseSelection doesn't re-mount on a resize, containerBoundingRect doesn't get reset to null and then re-initialised, breaking the calculated coords.

All this fix does is set containerBoundingRect to the latest clientRect whenever mouseDown is called. This adds some extra unnecessary overhead, but the alternative is resetting the variable on resize from the PdfHighlighter or remounting the MouseSelection entirely. I may have forgotten another way, though 😂.

I also just made a very small change to build:copy-styles to make it safer.