Skip to content

Commit

Permalink
Take into account caret position within Editable
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Feb 1, 2018
1 parent 7af36cb commit 6e75cd6
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions blocks/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,13 +751,23 @@ export default class RichText extends Component {
// focussed editor into view.
// Unfortunately we cannot detect virtual keyboards.
if ( window.innerWidth < 784 ) {
const rootNode = this.editor.getBody();

scrollIntoView( rootNode, rootNode.closest( '.edit-post-layout__content' ), {
// Give enough room for toolbar. Must be top.
// Unfortunately we cannot scroll to bottom as the
// virtual keyboard overlaps the window.
offsetTop: 100,
setTimeout( () => {
if ( this.editor.removed ) {
return;
}

const rootNode = this.editor.getBody();
const rootRect = rootNode.getBoundingClientRect();
const caretRect = this.editor.selection.getRng().getClientRects()[ 0 ];
const offset = caretRect ? caretRect.top - rootRect.top : 0;

scrollIntoView( rootNode, rootNode.closest( '.edit-post-layout__content' ), {
// Give enough room for toolbar. Must be top.
// Unfortunately we cannot scroll to bottom as the
// virtual keyboard overlaps the window.
offsetTop: 100 - offset,
alignWithTop: true,
} );
} );
}
}
Expand Down

0 comments on commit 6e75cd6

Please sign in to comment.