Skip to content

Commit

Permalink
Typewriter: use DOMRect.top to fix for Edge (#17707)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored and youknowriad committed Oct 2, 2019
1 parent a220eba commit 023cad3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/block-editor/src/components/typewriter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Typewriter extends Component {
return;
}

const diff = currentCaretRect.y - this.caretRect.y;
const diff = currentCaretRect.top - this.caretRect.top;

if ( diff === 0 ) {
return;
Expand All @@ -148,10 +148,10 @@ class Typewriter extends Component {
scrollContainer.scrollTop;
const scrollContainerY = windowScroll ?
0 :
scrollContainer.getBoundingClientRect().y;
scrollContainer.getBoundingClientRect().top;
const relativeScrollPosition = windowScroll ?
this.caretRect.y / window.innerHeight :
( this.caretRect.y - scrollContainerY ) /
this.caretRect.top / window.innerHeight :
( this.caretRect.top - scrollContainerY ) /
( window.innerHeight - scrollContainerY );

// If the scroll position is at the start, the active editable element
Expand All @@ -178,10 +178,10 @@ class Typewriter extends Component {
// view.
if (
// The caret is under the lower fold.
this.caretRect.y + this.caretRect.height >
this.caretRect.top + this.caretRect.height >
scrollContainerY + scrollContainerHeight ||
// The caret is above the upper fold.
this.caretRect.y < scrollContainerY
this.caretRect.top < scrollContainerY
) {
// Reset the caret position to maintain.
this.caretRect = currentCaretRect;
Expand Down

0 comments on commit 023cad3

Please sign in to comment.