Skip to content

Commit

Permalink
Utils: Document horizontal edge focusOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed May 3, 2018
1 parent 88e85f9 commit 1d2e112
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ export function isHorizontalEdge( container, isReverse ) {
return true;
}

const { focusNode, focusOffset: offset } = window.getSelection();

if ( isReverse && offset !== 0 ) {
// Focus offset accounts for direction of selection (offset where selection
// ends).
const { focusNode, focusOffset } = window.getSelection();
if ( isReverse && focusOffset !== 0 ) {
return false;
}

let node = focusNode;
const maxOffset = node.nodeType === TEXT_NODE ? node.nodeValue.length : node.childNodes.length;

if ( ! isReverse && offset !== maxOffset ) {
if ( ! isReverse && focusOffset !== maxOffset ) {
return false;
}

Expand Down

0 comments on commit 1d2e112

Please sign in to comment.