Closed Bug 324661 Opened 18 years ago Closed 13 years ago

designmode: bogus window.getSelection() results when selecting an image


(Core :: DOM: Selection, defect)

Not set





(Reporter: nine, Unassigned)




(Keywords: testcase)

See testcase on attached URL

The testcase is a simple desingmode WYSIWYG editor with an mouseup event handler that should tell which element is selected. In real life I want to display some properties of the selected element (e.g. the image's alt and title attributes) for editing. I get always the containing element, instead of the image element itself.

Reproducibility: always

Steps to reproduce:
1. go to the testcase URL
2. click on the Mozilla icon in the edit area

Actual Result:
An alert window with the following data about the selection:
anchorNode: [object HTMLParagraphElement] anchorOffset: 3 focusNode: [object HTMLParagraphElement] focusOffset: 4

Expected Result:
An alert window with something like this as selection data:
anchorNode: [object HTMLImageElement] anchorOffset: 0 focusNode: [object HTMLImageElement] focusOffset: 0
that is: the image element itself

Note: "expected" is the right word. It's how I imagine this should work (did not find documentation that says otherwise). Using the anchorOffset gives me the same result (the image element) but it's unclear why I have to use it in the first place. And it makes no sense for me that the focusOffset is the next element (the text node), which is not even selected. So it would leave the question of how I could detect wether an image was selected or some text containing the image.

tested on: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9a1) Gecko/20060125 Firefox/1.6a1, Seamonkey Beta 1 and Firefox 1.5/Windows
Blocks: 424615
Assignee: general → nobody
QA Contact: ian → general
Stefan, your test case is no longer available. Could you attach a new one?
I updated the URL. Test case is available again. Behaviour is still the same on Firefox 4.0 Beta 11
Thank you!

Chrome doesn't actually select the image, Opera has anchorOffset == focusOffset == 3. It's not clear to me what we want the behaviour to be here. Ehsan?
Component: DOM → Selection
QA Contact: general → selection
Hardware: x86 → All
This looks correct: the selection range is precisely one that selects the image and nothing else.  The range under "expected results" in comment 0 would select the _children_ of the image.

To be clear, the "anchor" and "focus" stuff are just the endpoints of the selection range (in the DOM 2 Range sense).  Everything else follows from that.
Closed: 13 years ago
Resolution: --- → INVALID
And in particular, think about what the anchor and focus stuff should look like if you have two images next to each other and select both of them.
You need to log in before you can comment on or make changes to this bug.