Open Bug 377297 Opened 17 years ago Updated 3 years ago

Cursor position is not retained when adding range to selection using getSelection() and addRange()

Categories

(Core :: DOM: Editor, defect, P5)

x86
Windows XP
defect

Tracking

()

People

(Reporter: mfenniak-moz, Unassigned)

Details

(Keywords: testcase)

Attachments

(4 files)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3

Setting a selection range always places the cursor at the end of the new range.  There does not appear to be a way to place the cursor anywhere else.

Reproducible: Always

Steps to Reproduce:
1. In the test case editor, enter some text.
2. With the cursor at the end of the text, hold down shift and press the
left-arrow key a couple of times to select backwards.
3. The test page automatically deselects and re-selects the selected text very second.  Wait a second.
Actual Results:  
Cursor is placed at the end of selection range.

Expected Results:  
Cursor is not moved.
Attached file minimal test case
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: testcase
Summary: set selection range moves cursor to end → Cursor position is not retained when adding range to selection using getSelection() and addRange()
Version: unspecified → Trunk
Jonas - can you take a look?
Flags: blocking1.9?
The obvious suggestion is to specify a reverse range, with the end preceding the start.  Whether this is W3 legal or not, is another question.  Regardless, reversing the range currently does not work, as demonstrated by the following example.  The range is automatically collapsed.
Attached file Reversed range
Reversed ranges are not allowed by the spec
Attached file Two ranges
A potential fix is to define two ranges: the first one collapsed (where the cursor goes), the second one spanning the selection.  This sort of works.  If you load the attached file, hold shift, and cursor left, you will see that the cursor was in the right spot.  But if you cursor right, the selection does not get reduced.  This is because there are now two selections on the page, one static, the other controlled by the cursor.

However, maybe this could be developed into a strategy for positioning the cursor.  Also required would be a strategy for getting the cursor location.
Flags: blocking1.9? → blocking1.9-
Whiteboard: [wanted-1.9]
a better work around is to use getSelection().extend() method. 
See selection_test_fixed.html
(I also wish same is available for TEXTAREA)

>  range.setStart(p, 10);
>  range.setEnd(p, 6);
W3C Spec dont allow setting End before Start.

That said, I dont see any reason why we forget anchor/focus position in "minimal test case"  while doing addRange with out setting the Start and End
Flags: wanted1.9+
Whiteboard: [wanted-1.9]
Flags: wanted1.9-
Flags: wanted1.9+
Flags: wanted-next+

Bulk-downgrade of unassigned, >=5 years untouched DOM/Storage bugs' priority.

If you have reason to believe this is wrong (especially for the severity), please write a comment and ni :jstutte.

Severity: normal → S4
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: