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

Container coordinates are not recalculated when scroll changes #226

Closed yfandino closed 2 weeks ago

yfandino commented 1 year ago

If the viewer is not in full size mode, and the highlight selection has been started. If you scroll down the page and try to make another highlight selection, the coordinates are incorrect (The highlight area is rendered in another position).

This is because the containerCoords function in MouseSelection.js gets the coordinates only at the start of the selection.

This could be solved getting the container bounding rect every time.

const containerCoords = (pageX, pageY) => {
    containerBoundingRect = container.getBoundingClientRect();

    return {
      x: pageX - containerBoundingRect.left + container.scrollLeft,
      y: pageY - containerBoundingRect.top + container.scrollTop - window.scrollY
    };
};