Summary: | window.getSelection() doesn't work in textareas | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Steven Tamm <stamm> | ||||
Component: | DOM | Assignee: | Nobody <webkit-unassigned> | ||||
Status: | NEW --- | ||||||
Severity: | Major | CC: | ap, dgatwood, gavin.sharp, ian, justin.garcia, rniwa, xan.lopez | ||||
Priority: | P2 | ||||||
Version: | 420+ | ||||||
Hardware: | Mac | ||||||
OS: | OS X 10.4 | ||||||
Attachments: |
|
Description
Steven Tamm
2006-02-15 08:40:34 PST
Confirming as a difference between Firefox and WebKit, but I am not sure what the correct approach would be. In Firefox, window.getSelection() returns a collapsed range positioned before the TEXTAREA (HTMLBodyElement, offset 22 in your example). This doesn't look right to me - that is an entirely different position, and the insertion point can easily be moved there in contenteditable mode. TEXTAREA has a child text node - perhaps it would be more appropriate to make window.getSelection() return the actual range within this text node? BTW, you can probably use onfocus/onblur handlers to track the last focused textarea. > BTW, you can probably use onfocus/onblur handlers to track the last focused
textarea.
This didn't work with 418 because onblur didn't get called appropriately when you click on a button
This fails similarly for anything set to contentEditable, too. I've been smashing my head against a wall over this bug off and on for months. (In reply to comment #3) > This fails similarly for anything set to contentEditable, too. Could you please provide a test case (preferably, in a new bug, to keep this one focused on textareas)? This seems to work correctly to me. Created attachment 20565 [details]
test case (same as is pasted as text in comments below)
FWIW, I recently stumbled upon this bug and I think nowadays we do what comment #1 (from 2006!) says Firefox used to do back then. The thing that makes this fail is DOMSelection.cpp:getRangeAt, which has a chunk like: if (Node* shadowAncestor = selectionShadowAncestor(m_frame)) { ContainerNode* container = shadowAncestor->parentNodeGuaranteedHostFree(); int offset = shadowAncestor->nodeIndex(); return Range::create(shadowAncestor->document(), container, offset, container, offset); } triggered inside text areas (and that makes us return a 0-0 bogus range). If I just *remove* that code, my simple tests seem to work OK, but I'm sure that breaks something else somewhere. Opinions? |