WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED DUPLICATE of
bug 216325
Bug 23600
Selection.collapse does not work as expected on empty text nodes
https://bugs.webkit.org/show_bug.cgi?id=23600
Summary
Selection.collapse does not work as expected on empty text nodes
Eric Seidel (no email)
Reported
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>
Attachments
test case
(1.06 KB, text/html)
2009-01-28 13:50 PST
,
Eric Seidel (no email)
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Eric Seidel (no email)
Comment 1
2009-01-28 13:50:08 PST
Created
attachment 27121
[details]
test case
Eric Seidel (no email)
Comment 2
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.
Justin Garcia
Comment 3
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.
Eric Seidel (no email)
Comment 4
2009-03-16 17:44:58 PDT
I think this in the end is just another dupe of
bug 15256
.
Ahmad Saleem
Comment 5
2022-12-16 16:14:26 PST
Using attached test case: *** Safari Technology Preview 160 *** comparing point with <text>, offset 0: FAILED: result = 1 expected 0 range: startContainer: [object HTMLBodyElement] startOffset: 0 endContainer: [object HTMLBodyElement] endOffset: 0 selection: anchorNode: [object HTMLBodyElement] anchorOffset: 0 focusNode: [object HTMLBodyElement] focusOffset: 0 *** Chrome Canary 110 & Firefox Nightly 110 *** comparing point with <text>, offset 0: PASSED: result = 0 range: startContainer: [object Text] startOffset: 0 endContainer: [object Text] endOffset: 0 selection: anchorNode: [object Text] anchorOffset: 0 focusNode: [object Text] focusOffset: 0 ____ Just wanted to share updated test result. Thanks!
Darin Adler
Comment 6
2022-12-17 19:20:58 PST
Probably fixed by the live range selection work that Ryosuke is doing.
Ryosuke Niwa
Comment 7
2022-12-17 22:05:15 PST
Indeed, this test case passes once live range selection is enabled.
Ryosuke Niwa
Comment 8
2022-12-17 22:05:29 PST
*** This bug has been marked as a duplicate of
bug 216325
***
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug