Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
654eb22
Writing Flow: Collapse range in horizontal edge check by direction
aduth Apr 27, 2018
f7dcc8a
Try alternative approach
ellatrix Apr 30, 2018
bef44c3
Writing Flow: Move collapsed selection condition to WritingFlow
aduth May 2, 2018
a8728bf
Writing Flow: Vertical navigate from uncollapsed selections
aduth May 2, 2018
79fc388
Writing Flow: Use Selection#isCollapsed in place of hasCollapsedSelec…
aduth May 2, 2018
83d3ff7
Rich Text: Verify collapsed selection in delete behavior
aduth May 2, 2018
33184f9
Utils: Improve range rect detection for br-separated content
aduth May 2, 2018
f2ae9ef
Testing: Add Writing Flow E2E tests
aduth May 2, 2018
d81ac98
Try getRectangleFromRange fix without manipulating live DOM
ellatrix May 2, 2018
284900e
Utils: Update caret to selection in edge tests comments
aduth May 3, 2018
bc252af
Writing Flow: Invert position when isReverse not aligned to backward
aduth May 3, 2018
a961282
Try direct selection
ellatrix May 3, 2018
6431770
Only look at focusNode
ellatrix May 3, 2018
c0a0fc3
Utils: Document horizontal edge focusOffset
aduth May 3, 2018
b5a54df
Utils: Use temporary text node for rect fallback
aduth May 3, 2018
e087ddd
Writing Flow: Test horizontal navigation as handled
aduth May 3, 2018
7b174ad
Element: Fix Fragment render error on empty children
aduth May 10, 2018
a528868
Testing: Add global guard against ZWSP in E2E content retrieval
aduth May 10, 2018
d6f1ab9
RichText: Remove ZWSP on focusout
aduth May 10, 2018
4523390
RichText: Consider emptiness by Children count utility
aduth May 10, 2018
31596df
Writing Flow: Consider horizontal handled by stopPropagation in RichText
aduth May 10, 2018
fa4ad6d
RichText: Get content by converting tree node to element
aduth May 10, 2018
2afb649
Writing Flow: Consider as edge by effective caret position
aduth May 10, 2018
dab93de
Rich Text: Return element fragment as array
aduth May 10, 2018
9dde841
Testing: Attempt to resolve race conditions with TinyMCE initialization
aduth May 10, 2018
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: Collapse range in horizontal edge check by direction
  • Loading branch information
aduth committed May 9, 2018
commit 654eb22858e6cbbab278fb90aaef0f586d43bdab
36 changes: 34 additions & 2 deletions utils/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,37 @@ import tinymce from 'tinymce';
* Browser dependencies
*/
const { getComputedStyle, DOMRect } = window;
const { TEXT_NODE, ELEMENT_NODE } = window.Node;
const { TEXT_NODE, ELEMENT_NODE, DOCUMENT_POSITION_PRECEDING } = window.Node;

/**
* Returns true if the given selection object is in the forward direction, or
* false otherwise.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
*
* @param {Selection} selection Selection object to check.
*
* @return {boolean} Whether the selection is forward.
*/
function isSelectionForward( selection ) {
const {
anchorNode,
focusNode,
anchorOffset,
focusOffset,
} = selection;

const position = anchorNode.compareDocumentPosition( focusNode );

return (
// Compare whether anchor node precedes focus node.
position !== DOCUMENT_POSITION_PRECEDING &&

// `compareDocumentPosition` returns 0 when passed the same node, in
// which case compare offsets.
! ( position === 0 && anchorOffset > focusOffset )
);
}

/**
* Check whether the caret is horizontally at the edge of the container.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might want to update "caret" to "selection", as "caret" implies a collapsed selection I think.

Expand Down Expand Up @@ -45,7 +75,9 @@ export function isHorizontalEdge( container, isReverse, collapseRanges = false )
let range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;
if ( collapseRanges ) {
range = range.cloneRange();
range.collapse( isReverse );

// Collapse to the extent of the selection by direction.
range.collapse( ! isSelectionForward( selection ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the goal to set this range to the document? This is just used for calculation purposes (a clone) right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure here how the direction of a selection relates to this check. This would collapse a range at the edge of a field to the end or the start depending on direction (so in one case this will collapse to the end and the check fails), while we should check whether or not the range touches the edge? See 1bb9658

}

if ( ! range || ! range.collapsed ) {
Expand Down