Closed Bug 1037004 Opened 10 years ago Closed 7 years ago

Setting the selection on an unfocused contenteditable node results in a broken cursor

Categories

(Core :: DOM: Editor, defect)

30 Branch
defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: ejsanders, Unassigned)

Details

(Keywords: testcase)

Attachments

(1 file)

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0 (Beta/Release)
Build ID: 20140608211622

Steps to reproduce:

See http://jsfiddle.net/edg2s/HA9qt/



Expected results:

Either set selection gives focus to the other CE (as in Chrome), or it results in a greyed out unfocused selection where typing does nothing.
I can reproduce this on OS X.
Status: UNCONFIRMED → NEW
Component: Untriaged → Editor
Ever confirmed: true
Keywords: testcase
OS: Linux → All
Product: Firefox → Core
Hardware: x86_64 → All
Summary: Setting the selection on an unfocused contenteditable node results in an broken cursor → Setting the selection on an unfocused contenteditable node results in a broken cursor
Moved to editor, but I guess it's also possible Core::Selection is a better place - out of interest, does the same not happen with plain <input> fields?
Flags: needinfo?(ejsanders)
Input fields don't use Selection.addRange, they use HTMLInputElement.setSelectionRange. If you call this on an unfocused input, nothing happens: http://jsfiddle.net/4t9Vv/ (in Chrome, it again gives focus to the thing being selected).
Flags: needinfo?(ejsanders)
Firefox has different behavior depending on where the cursor was before javascript attempts to place it in a content editable.

This attachment contains instructions and code for 3 test cases, differentiated by what (if anything) has the text cursor before javascript tries to place it within a contenteditable:

1: There is no cursor/focus initially. In this case firefox fails to place focus/cursor in the contenteditable.

2: The cursor/focus is within a different contenteditable. In this case Firefox places the cursor into the correct contenteditable, in the correct location... but the cursor does not move when you type, resulting in the text you type being inserted in reverse order (siht ekil)

3: The cursor is already in the correct contenteditable. In this case Firefox works correctly, ie the cursor is moved to the end of the text, and typing works as expected.


P.S. A workaround would be very much appreciated. I really want to be able to place the cursor in some contenteditables in my project.
WORKAROUND: call editable_div.focus() first, before doing the range stuff.
I cannot reproduce this on 56, but I can reproduce this on 54.  I believe that this might be fixed by bug 1318312.  Mark as WFM.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: