From 0391e1855cd5c770928a3b4252aef54ed0a51385 Mon Sep 17 00:00:00 2001 From: "jeremy@jermolene.com" Date: Thu, 16 Jun 2022 17:00:20 +0100 Subject: [PATCH] Fix new selection tracker to return relative coordinates --- plugins/tiddlywiki/dynannotate/modules/selection-tracker.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/tiddlywiki/dynannotate/modules/selection-tracker.js b/plugins/tiddlywiki/dynannotate/modules/selection-tracker.js index 616bedd29..6b74d0c4b 100644 --- a/plugins/tiddlywiki/dynannotate/modules/selection-tracker.js +++ b/plugins/tiddlywiki/dynannotate/modules/selection-tracker.js @@ -139,9 +139,9 @@ SelectionTracker.prototype.handleSelectionChange = function() { var variables = {}; // Get the bounds of the container and the selection var selectionRectangle = selection.getRangeAt(0).getBoundingClientRect(), - trackingRectangle = anchor.container.parentNode.getBoundingClientRect(); - variables["tv-selection-posx"] = (selectionRectangle.left).toString(); - variables["tv-selection-posy"] = (selectionRectangle.top).toString(); + offsetParentRectangle = anchor.container.offsetParent.getBoundingClientRect(); + variables["tv-selection-posx"] = (selectionRectangle.left - offsetParentRectangle.left).toString(); + variables["tv-selection-posy"] = (selectionRectangle.top - offsetParentRectangle.top).toString(); variables["tv-selection-width"] = (selectionRectangle.width).toString(); variables["tv-selection-height"] = (selectionRectangle.height).toString(); variables["tv-selection-coords"] = "(" + variables["tv-selection-posx"] + "," + variables["tv-selection-posy"] + "," + variables["tv-selection-width"] + "," + variables["tv-selection-height"] + ")";