Skip to content

Commit

Permalink
fix: consider scroll position for the coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
0x04 committed Sep 25, 2024
1 parent ecec447 commit f835147
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/classes/mouse-grid.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ export class MouseGrid {
}

getPointFromEvent(event) {
const { scrollTop, scrollLeft } = event.target

return this.getPointFromCoordinate(
event.offsetX - this.gridRect.x,
event.offsetY - this.gridRect.y
scrollLeft + event.offsetX - this.gridRect.x,
scrollTop + event.offsetY - this.gridRect.y
)
}
}
2 changes: 1 addition & 1 deletion src/components/canvas.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Canvas {

element.innerText = data.toString()

this.rectangle = new Rectangle(0, 0, element.clientWidth, element.clientHeight)
this.rectangle = new Rectangle(0, 0, element.scrollWidth, element.scrollHeight)
this.mouseGrid = new MouseGrid(this.rectangle, this.metrics.rectangle)
}

Expand Down

0 comments on commit f835147

Please sign in to comment.