From f83514720a913b02b6dc84c48394b35efc4385ad Mon Sep 17 00:00:00 2001 From: 0x04 Date: Wed, 25 Sep 2024 21:23:46 +0200 Subject: [PATCH] fix: consider scroll position for the coordinates --- src/classes/mouse-grid.mjs | 6 ++++-- src/components/canvas.mjs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/classes/mouse-grid.mjs b/src/classes/mouse-grid.mjs index da940df..0ea7f0f 100644 --- a/src/classes/mouse-grid.mjs +++ b/src/classes/mouse-grid.mjs @@ -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 ) } } diff --git a/src/components/canvas.mjs b/src/components/canvas.mjs index 694b287..2174ce3 100644 --- a/src/components/canvas.mjs +++ b/src/components/canvas.mjs @@ -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) }