Bug 23600 - Selection.collapse does not work as expected on empty text nodes
Summary: Selection.collapse does not work as expected on empty text nodes
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: 528+ (Nightly build)
Hardware: Macintosh OS X 10.5
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on: 15256 23601
Blocks:
  Show dependency treegraph
 
Reported: 2009-01-28 13:49 PST by Eric Seidel (no email)
Modified: 2009-03-16 17:44 PDT (History)
5 users (show)

See Also:


Attachments
test case (1.06 KB, text/html)
2009-01-28 13:50 PST, Eric Seidel (no email)
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Seidel (no email) 2009-01-28 13:49:50 PST
Ojan and I were trying to use comparePoint in a test case.  It didn't work like we thought it would.  After some investigation, it just seems our ranges are borked.  This is probably a dupe of the "VisualPosiition shouldn't be used as much as they are" bug.

Test case:
<html>
<body>
    <div id='log'></div>
<script>
function debug(str) {
    var logger = document.getElementById('log');
    logger.appendChild(document.createTextNode(str));
    logger.appendChild(document.createElement('br'));
}
var div = document.createElement('div');
document.body.appendChild(div);
var textNode = document.createTextNode("");
div.appendChild(textNode);

var sel = window.getSelection();
sel.collapse(textNode, 0);
var range = sel.getRangeAt(0);

debug("comparing point with <text>, offset 0:");
var result = range.comparePoint(textNode, 0);
if (result == 0) {
    debug("PASSED: result = 0");
} else {
    debug("FAILED: result = " + result + " expected 0");
}

debug("range:");
debug("startContainer: " + range.startContainer);
debug("startOffset: " + range.startOffset);
debug("endContainer: " + range.endContainer);
debug("endOffset: " + range.endOffset);

debug("selection:");
debug("anchorNode: " + sel.anchorNode);
debug("anchorOffset: " + sel.anchorOffset);
debug("focusNode: " + sel.focusNode);
debug("focusOffset: " + sel.focusOffset);
</script>
</body>
</html>
Comment 1 Eric Seidel (no email) 2009-01-28 13:50:08 PST
Created attachment 27121 [details]
test case
Comment 2 Eric Seidel (no email) 2009-01-28 13:54:29 PST
Ok, turns out there are at least two bugs at play.  Repurposing this one to cover "Range.collapse does not work as expected on empty text nodes", and will file a separate bug with slightly modified test case showing more clearly that getRangeAt(0) is mutating the Range in a bad bad way.
Comment 3 Justin Garcia 2009-01-28 15:16:13 PST
(In reply to comment #2)
> Ok, turns out there are at least two bugs at play.  Repurposing this one to
> cover "Range.collapse does not work as expected on empty text nodes

Looks like you're using Selection.collapse not Range.collapse.
Comment 4 Eric Seidel (no email) 2009-03-16 17:44:58 PDT
I think this in the end is just another dupe of bug 15256.