Issue 526516 in chromium: <textarea> selectionStart always returns 0 in focus event

182 views
Skip to first unread message

chro...@googlecode.com

unread,
Aug 30, 2015, 11:36:22 AM8/30/15
to chromi...@chromium.org
Status: Unconfirmed
Owner: ----
Labels: Cr-Blink Pri-2 Via-Wizard Type-Bug OS-Mac

New issue 526516 by antonio....@gmail.com: <textarea> selectionStart always
returns 0 in focus event
https://code.google.com/p/chromium/issues/detail?id=526516

UserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36

Example URL:

Steps to reproduce the problem:
1. Copy the HTML below
2. Write in the <textarea> and move the cursor in the middle of the text
3. Click the button Focus and see that 0 is logged in the console

<textarea id="text"></textarea>
<button onclick="document.getElementById('text').focus();">Focus</button>
<script>
var textarea = document.getElementById('text');
textarea.addEventListener('focus', function (e) {
console.log(textarea.selectionStart);
});
</script>

What is the expected behavior?
The textarea.selectionStart should return the cursor position not zero. In
every other page state it returns the correct value.

P.S.: The problem could also be replicated for the selectionEnd property.

What went wrong?
The console prints 0 because textarea.selectionStart is incorrect.

Does it occur on multiple sites: Yes

Is it a problem with a plugin? No

Did this work before? N/A

Does this work in other browsers? Yes

Chrome version: 44.0.2403.157 Channel: stable
OS Version: OS X 10.9.5
Flash Version: Shockwave Flash 18.0 r0

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

chro...@googlecode.com

unread,
Aug 30, 2015, 10:22:26 PM8/30/15
to chromi...@chromium.org
Updates:
Status: Available
Labels: -Cr-Blink Cr-Blink-Forms Cr-Blink-Forms-Textarea Hotlist-Interop

Comment #1 on issue 526516 by tk...@chromium.org: <textarea> selectionStart
Confirmed.

chro...@googlecode.com

unread,
Nov 10, 2015, 12:34:09 AM11/10/15
to chromi...@chromium.org
Updates:
Status: Started
Owner: tk...@chromium.org

Comment #2 on issue 526516 by tk...@chromium.org: <textarea> selectionStart
(No comment was entered for this change.)

chro...@googlecode.com

unread,
Nov 10, 2015, 1:57:32 PM11/10/15
to chromi...@chromium.org

Comment #3 on issue 526516 by bugd...@chromium.org: <textarea>
selectionStart always returns 0 in focus event
https://code.google.com/p/chromium/issues/detail?id=526516#c3

The following revision refers to this bug:

https://chromium.googlesource.com/chromium/src.git/+/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b

commit 7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b
Author: tkent <tk...@chromium.org>
Date: Tue Nov 10 18:35:49 2015

Introduce a struct to store arguments of Element::focus().

Also, converts the |restorePreviousSelection| argument to an enum class.
This CL has no behavior changes, and improves code readability.

BUG=526516

Review URL: https://codereview.chromium.org/1420693006

Cr-Commit-Position: refs/heads/master@{#358859}

[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/dom/Document.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/dom/Document.h
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/dom/Element.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/dom/Element.h
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/HTMLAreaElement.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/HTMLAreaElement.h
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/HTMLInputElement.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/HTMLInputElement.h
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/HTMLLabelElement.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/HTMLLabelElement.h
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/HTMLLegendElement.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/HTMLLegendElement.h
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/HTMLSelectElement.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/HTMLTextAreaElement.h
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/forms/InputType.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/html/forms/TextFieldInputType.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/input/EventHandler.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/core/page/FocusController.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/web/WebFrameWidgetImpl.cpp
[modify]
http://crrev.com/7e0e1b14e1033e03fa1dc772e2c44dfb45a7888b/third_party/WebKit/Source/web/WebViewImpl.cpp

chro...@googlecode.com

unread,
Nov 11, 2015, 4:24:21 AM11/11/15
to chromi...@chromium.org

Comment #4 on issue 526516 by bugd...@chromium.org: <textarea>
selectionStart always returns 0 in focus event
https://code.google.com/p/chromium/issues/detail?id=526516#c4

The following revision refers to this bug:

https://chromium.googlesource.com/chromium/src.git/+/99a0f4166c156b1bcd64ffd8b04a087a311175d3

commit 99a0f4166c156b1bcd64ffd8b04a087a311175d3
Author: tkent <tk...@chromium.org>
Date: Wed Nov 11 09:21:33 2015

Use FocusParams in FocusController::setFocusedElement and
Document::setFocusedElement arguments.

Adds a FocusController::setFocusedElement overload and
Document::clearFocusedElement
to simplify the code.

These functions receive unused SelectionBehaviorOnFocus as a member of
FocusParams.
We'll start to use SelectionBehaviorOnFocus in these functions later.

This CL introduces SelectionBehaviorOnFocus::None for setFocusedElement
callsites other than Element::focus.

This CL has no behavior changes.

BUG=526516

Review URL: https://codereview.chromium.org/1433103002

Cr-Commit-Position: refs/heads/master@{#359073}

[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/dom/Document.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/dom/Document.h
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/dom/Element.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/dom/Element.h
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/editing/FrameSelection.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/frame/FrameView.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/html/HTMLDialogElement.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/html/HTMLInputElement.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/html/forms/RadioInputType.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/input/EventHandler.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/page/FocusController.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/page/FocusController.h
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/core/testing/Internals.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/web/TextFinder.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/web/WebLocalFrameImpl.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/web/WebPluginContainerImpl.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/web/WebViewImpl.cpp
[modify]
http://crrev.com/99a0f4166c156b1bcd64ffd8b04a087a311175d3/third_party/WebKit/Source/web/tests/WebViewTest.cpp

chro...@googlecode.com

unread,
Nov 19, 2015, 5:40:20 AM11/19/15
to chromi...@chromium.org

Comment #5 on issue 526516 by bugd...@chromium.org: <textarea>
selectionStart always returns 0 in focus event
https://code.google.com/p/chromium/issues/detail?id=526516#c5

The following revision refers to this bug:

https://chromium.googlesource.com/chromium/src.git/+/d76505b8d68f4fffd18620d9ab1b4d19c467ec4c

commit d76505b8d68f4fffd18620d9ab1b4d19c467ec4c
Author: tkent <tk...@chromium.org>
Date: Thu Nov 19 10:34:51 2015

Set selection to INPUT/TEXTAREA before dispatching 'focus' event.

This CL moves updateFocusAppearance() call from Element::focus() to
Document::setFocusedElement() so that 'focus' event handler can refer to
correct
selection information.

The last updateLayoutIgnorePendingStylesheets() call in Element::focus is
unnecessary now. Because this CL removes it,
textfield-to-password-on-focus.html needs a delay to pour key inputs.

BUG=526516

Review URL: https://codereview.chromium.org/1437813002

Cr-Commit-Position: refs/heads/master@{#360545}

[modify]
http://crrev.com/d76505b8d68f4fffd18620d9ab1b4d19c467ec4c/third_party/WebKit/LayoutTests/fast/forms/selection-functions-expected.txt
[modify]
http://crrev.com/d76505b8d68f4fffd18620d9ab1b4d19c467ec4c/third_party/WebKit/LayoutTests/fast/forms/selection-functions.html
[modify]
http://crrev.com/d76505b8d68f4fffd18620d9ab1b4d19c467ec4c/third_party/WebKit/LayoutTests/fast/forms/textfield-to-password-on-focus.html
[modify]
http://crrev.com/d76505b8d68f4fffd18620d9ab1b4d19c467ec4c/third_party/WebKit/Source/core/dom/Document.cpp
[modify]
http://crrev.com/d76505b8d68f4fffd18620d9ab1b4d19c467ec4c/third_party/WebKit/Source/core/dom/Element.cpp
[modify]
http://crrev.com/d76505b8d68f4fffd18620d9ab1b4d19c467ec4c/third_party/WebKit/Source/core/html/HTMLInputElement.cpp
[modify]
http://crrev.com/d76505b8d68f4fffd18620d9ab1b4d19c467ec4c/third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp

chro...@googlecode.com

unread,
Nov 19, 2015, 6:00:22 PM11/19/15
to chromi...@chromium.org
Updates:
Status: Fixed
Labels: M-49

Comment #6 on issue 526516 by tk...@chromium.org: <textarea> selectionStart
always returns 0 in focus event
https://code.google.com/p/chromium/issues/detail?id=526516

(No comment was entered for this change.)

Reply all
Reply to author
Forward
0 new messages