Skip to content

Commit

Permalink
text: fix getSelectionBounds() in scaled world (for real)
Browse files Browse the repository at this point in the history
  • Loading branch information
codefrau authored and lively-web committed Jan 20, 2017
1 parent 0b08f69 commit b57bd7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions core/lively/morphic/Graphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,10 @@ Object.subclass('lively.Rectangle',
return new lively.Rectangle(this.x + d.x, this.y + d.y, this.width, this.height);
},

scaledBy: function(s) {
return new lively.Rectangle(this.x * s, this.y * s, this.width * s, this.height * s);
},

scaleByRect: function(r) {
// r is a relative rect, as a pane spec in a window
return new lively.Rectangle(
Expand Down
5 changes: 3 additions & 2 deletions core/lively/morphic/TextCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2083,12 +2083,13 @@ lively.morphic.Morph.subclass('lively.morphic.Text', Trait('TextChunkOwner'),
// https://developer.mozilla.org/en-US/docs/Web/API/Selection
var domRect = sel.getRangeAt(0).getBoundingClientRect(),
scale = this.world() ? this.world().getScale(): 1;
// 2. make a livelyRectangle from the DOMSelection rect scaled by world scale
return rect(domRect.left/scale, domRect.top/scale, domRect.width/scale, domRect.height/scale)
// 2. make a livelyRectangle from the DOMSelection rect
return rect(domRect.left, domRect.top, domRect.width, domRect.height)
// 3. the DOM selection is in absolute (world) coordinates offsetted by the
// current scroll of web browser window. Remove that offset:
// make them absolute
.translatedBy(pt($win.scrollLeft(), $win.scrollTop()))
.scaledBy(1 / scale)
// the rectangle does not take the scroll value of the morph into account, add it
.translatedBy(pt(scroll[0], scroll[1]))
// we now make that rectnagle local so that it can be compared to
Expand Down

0 comments on commit b57bd7d

Please sign in to comment.