Skip to content

Commit

Permalink
Fallback to parent coords in tether-to-selection (#141)
Browse files Browse the repository at this point in the history
A user reported that the link prompt was always offscreen. I traced this down to `range.getBoundingClient()` returning zero for dimensions and coords in certain cases—I was able to duplicate most reliably by opening a blank editor, hitting “enter”, hitting the “up” key, and finally hitting the link button.

Cases that trigger the issue seemed more prevalent in release Safari than in release Chrome for whatever reason. I could not find the root “cause” of the zeroed-out attributes, but found that falling back to `startContainer` works fine from a UI perspective.
  • Loading branch information
dtetto authored and bantic committed Oct 1, 2017
1 parent 6036bd0 commit 1bfd8ca
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions addon/components/tether-to-selection/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export default Component.extend({

if (range) {
let rect = range.getBoundingClientRect();
// Fallback on parent element container if no anchor container found:
if (!rect.left && !rect.top) rect = range.startContainer.getBoundingClientRect()
this.set('left', rect.left);
this.set('top', rect.top);
}
Expand Down

0 comments on commit 1bfd8ca

Please sign in to comment.