Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Writing Flow: fix list selection
  • Loading branch information
ellatrix committed Jan 17, 2020
commit 4d30890c1690c2095dd5c7dd278d608278d14dbd
23 changes: 22 additions & 1 deletion packages/dom/src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ function isSelectionForward( selection ) {
return true;
}

function normaliseRange( range ) {
range = range.cloneRange();

const { startContainer, startOffset } = range;

if (
startContainer.nodeType === startContainer.TEXT_NODE &&
startContainer.nodeValue.length === startOffset
) {
let element = startContainer;

while ( ! element.nextSibling ) {
element = element.parentNode;
}

range.setStart( element.nextSibling, 0 );
}

return range;
}

/**
* Check whether the selection is at the edge of the container. Checks for
* horizontal position by default. Set `onlyVertical` to true to check only
Expand Down Expand Up @@ -93,7 +114,7 @@ function isEdge( container, isReverse, onlyVertical ) {
return false;
}

const range = selection.getRangeAt( 0 ).cloneRange();
const range = normaliseRange( selection.getRangeAt( 0 ) );
const isForward = isSelectionForward( selection );
const isCollapsed = selection.isCollapsed;

Expand Down