Range.getClientRects() returns an empty list when selecting an empty text node
Reported by
eric.rannaud@gmail.com,
May 4 2018
|
||||
Issue descriptionUserAgent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36 Steps to reproduce the problem: 1. Open http://jsbin.com/nupinokisu/1/edit?html,js,output 2. Observe "Case 2" in the output on the right 3. The rect list returned by getClientRects() is empty What is the expected behavior? The DOMRectList should contain a DOMRect corresponding to the empty text node that was inserted in the DIV#emptytextnode (see init in the JS code). Firefox behaves better and returns the rect "left 8 top 8 width 0 height 0" (the height probably shouldn't be 0, though). What went wrong? Case 2 places an empty text node inside a DIV. Then a Range is built with startContainer and endContainer set to the empty text node, with startOffset and endOffset set to 0. Range.getClientRects() returns an empty rect list. The spec is clear: https://drafts.csswg.org/cssom-view/#extensions-to-the-range-interface "For each Text node selected or partially selected by the range (including when the boundary-points are identical), include a DOMRect object (for the part that is selected, not the whole line box)." The spec does not make an exception for empty text nodes. Related issues: (Case 3) https://bugs.chromium.org/p/chromium/issues/detail?id=435438 Fixed since 63: a collapsed range in the middle of a non-empty text node was returning an empty rect list. (Case 5) https://bugs.chromium.org/p/chromium/issues/detail?id=764841 Not yet fixed: a collapsed range in a long sequence of white spaces in the middle of a non-empty text node returns an empty rect list. (Case 1) https://bugs.chromium.org/p/chromium/issues/detail?id=830044 https://bugs.chromium.org/p/chromium/issues/detail?id=637296 These two issues regard a slightly different case: when the range "selects" either the inside of an empty Element, or selects between two Elements. The spec states that a collapsed range inside an empty text node or next to a text node does indeed (partially) selects the text node (and therefore getClientRect() shall return a non-empty rect list). But the spec is not clear on what happens when there is no text node around or next to a collapsed range. For these 2 issues, it is claimed that Chrome is behaving as expected, and that the spec may have to be changed, if we want to avoid a different behavior whether an empty text node is present or not (i.e. whether the containing node has been normalized or not). Did this work before? No Does this work in other browsers? Yes Chrome version: 66.0.3359.139 Channel: stable OS Version: Arch Flash Version: Please note that the test case is built using a plain DIV (which is not contenteditable). I don't believe the situation is any different with contenteditable set, though. This issue affects the result of getBoundingClientRect(): when an empty list is returned by getClientRects(), getBoundingClientRect() correctly returns a zero-filled DOMRect. Just making a note of this for anyone who would be searching for an issue concerning getBoundingClientRect(): the culprit is actually getClientRects().
,
May 6 2018
,
May 8 2018
Able to reproduce the issue on Mac 10.13.3, Win-10 and Ubuntu 17.10 using chrome reported version #66.0.3359.139 and latest canary #68.0.3423.2. This is a non-regression issue as it is observed from M60 old builds. Hence, marking it as untriaged to get more inputs from dev team. Thanks...!!
,
May 8 2018
|
||||
►
Sign in to add a comment |
||||
Comment 1 by eric.rannaud@gmail.com
, May 4 2018