Fix adder position when document or body position is offset. #493
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix positioning of the adder when the document and/or body elements are
positioned and offset relative to their default position.
There were two problems:
adder.js
andrange-util.js
failed to account for the documentelement's position being offset from the default (0, 0) location.
Adder#showAt
did not take into account the offset of the body element from the
top-left corner of the document element.
This commit fixes the issue by:
Using viewport coordinates as far as possible in the range-util and
Adder functions to reduce the need for converting coordinates.
Calculating the position of the adder by comparing the target
viewport coordinates for the adder and the viewport coordinates of
the adder's nearest positioned ancestor.
Fixes #487
Also fixes the issue described in #486
The easiest way to understand the changes is probably to look at the three tests added for
Adder#showAt
: https://github.com/hypothesis/client/pull/493/files#diff-a251082cf4ba541e58bd7fb2434e557bR135