Open Bug 1484953 Opened 6 years ago Updated 2 years ago

Selection.toString() is sometimes empty even when Range objects have content and there's a text selection

Categories

(Core :: DOM: Selection, defect, P3)

61 Branch
defect

Tracking

()

Tracking Status
firefox63 --- affected

People

(Reporter: daniel.rb.lobo, Unassigned)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

45.04 KB, application/x-zip-compressed
Details
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0
Build ID: 20180704003137

Steps to reproduce:

1. Open the attached package.
2. Check that, for each mouse up event, the JS code in page.html prints the results of document.getSelection().toString() and the concatenation of all Ranges in document.getSelection().
3. Open page.html in Firefox and open the web console.
4. Select just the "Some" word in the table. See that it prints:

selection.toString(): "Some"
all selection ranges: "Some"
[Screenshot "img1 - text selection.png" in package.]

5. Select the "Some" word AND the image. See that it prints [I hope whitespace is kept when posting here...]:

selection.toString(): " 	Some"
all selection ranges: "
			Some"
[Screenshot "img2 - text plus entire image.png" in package.]

6. Now select the "Some" word and keep dragging the mouse over the image, but release it before passing through its midpoint, so that it isn't selected but you still release the mouse while over it. See that it prints:

selection.toString(): ""
all selection ranges: "
			Some"
[Screenshot "img3 - text and release over image, before passing half of it.png" in package.]

7 (BONUS). Do the last example on Google Chrome. See that it prints:

selection.toString(): "	Some"
all selection ranges: "
			Some"
[Screenshot "img4 - same as 3, but on chrome.png" in package.]


Actual results:

As seen from the prints, the last example in Firefox has similar content to the second in the Range objects, but toString() returns empty! Chrome seems to handle this normally.

This also seems to affect the ability of the browser to detect that there is text selected, since the context menu doesn't even display the "Search Google for ()" option. WebExtensions that show the selected text in the context menu also won't appear when they use this:

	browser.contextMenus.create({
		(...)
		title: "Selected text is “%s”",
		(...)
	});


Expected results:

Even if the result of Selection.toString() is not necessarily the same as concatenating the contents of all Ranges (due to other DOM elements, for example) it should contain all selected text when there is text selected in the page.
Reproducible with the following specs:
Version 	63.0a1
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0
Build ID 	20180823100106
Status: UNCONFIRMED → NEW
Component: Untriaged → Selection
Ever confirmed: true
Product: Firefox → Core
Priority: -- → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: