New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 806233 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Feb 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Windows , Mac
Pri: 2
Type: Bug



Sign in to add a comment

setSelectionRange() doesn't move cursor (and selection) to the visible input area

Reported by nikolay....@gmail.com, Jan 26 2018

Issue description

UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36

Steps to reproduce the problem:
1. Open the following sample https://jsfiddle.net/Lipata/c02ux411/3/ 
2. Notice that the cursor is not visible. It is moved to 9th position, but the text is not moved and the cursor is hidden.
3. The same problem is valid when setSelectionRange() is called inside a event handler (e.g. keypress). At the first point I though the problem was caused because the preventDefault() is called, but I guess the root problem is the one with the setSelectionRange() method. 

What is the expected behavior?
The text is moved so that the cursor and current selections are visible

What went wrong?
The selection/cursor is not visible, when the text width is more than the input width.

Did this work before? N/A 

Does this work in other browsers? N/A

Chrome version: 63.0.3239.132  Channel: n/a
OS Version: 10.0
Flash Version:
 
Labels: Needs-Triage-M63
Able to reproduce the issue on reported chrome version 63.0.3239.132 and on the latest canary 66.0.3334.0 using Windows 10, Ubuntu 17.10 and Mac 10.13.1. As the issue is seen from M60(60.0.3072.0) considering it as non-regression and marking it as Untriaged.

Thanks!
Cc: viswatej...@techmahindra.com
Labels: Triaged-ET M-66 FoundIn-66 Target-66 OS-Linux OS-Mac
Status: Untriaged (was: Unconfirmed)
Thank you, guys!

Regards
Components: -Blink>JavaScript Blink
Not JS related.

Comment 6 by e...@chromium.org, Feb 8 2018

Components: -Blink Blink>Editing

Comment 7 by yosin@chromium.org, Feb 14 2018

Status: WontFix (was: Untriaged)
Default event handler for "keypress" moves selection but the sample script
doesn't.

Please use "input" event handler to capitalize input value, e.g.
https://jsfiddle.net/c02ux411/11/
Hi, guys.

Thank you for looking at this. I understand that "input" event is alternative for "keypress" handler, but can you guys give more information why is that. As far as I remember in older versions of Chrome this was working inside the "keypress" event handler.

Even though the problem of setting the selection inside the "input" event handler is a solution, still there is a problem of using setSelection(), outside the context of any event handler, like here:

https://jsfiddle.net/c02ux411/14/

Thank you in advance for the answer!

Regards,
Nikolay Alipiev

Comment 9 by yosin@chromium.org, Feb 15 2018

Components: -Blink>Editing Blink>Editing>Selection
# "input" is our friends
TL;DR: Use "input" for detecting change by user, use "keypress" only for game

We should handle "input" event to detect value change by user interaction.

Keyboard is one of way to enter a character, move/extend selection, delete
characters. IME, which uses keyboard, hand writing, voice, camera, etc, is
also change value by user interaction.

On smart phones, IME is main source of user input and all user inputs come
from IME by "compositionstart", "compositionupdate" and "compositionend".

For IME case, "keypress" event doesn't mean what user wants to input, e.g.
alphabet + accessnt(é), CJK (ka=か), etc, thus converting keyboard character
to upper case, we should use String.prototype.toLocaleUpperCase(), isn't
enough or does wrong.


# HTMLInput#setSelectionRange()
Please try to call Element#focus() after HTMLInput#setSelectionRange()[1].
In this way, INPUT element is scrolled to show caret[2], 
by FrameSelection::RevealSelection() via FrameSelection::SetSelectio().

When you call setSelectionRange() after focus()[4], Blink doesn't call RevealSelection()[3],
because setSelectionRange() calls SetSelection() with SetSelectionBy::kSystem.
  if (set_selection_by == SetSelectionBy::kUser) {
    ....
    RevealSelection(alignment, kRevealExtent);
  }

Note: All browsers behave different:

SetSelection before Focus[1]: 
- Chrome: reveal
- Edge: not reveal
- Firefox: not reveal

SetSelection after Focus[2]: 
- Chrome: not reveal
- Edge: reveal
- Firefox: not reveal

Could you ask which behavior is a good for developer as issue in [5]?

[1] https://jsfiddle.net/c02ux411/15/
[2] https://cs.chromium.org/chromium/src/third_party/WebKit/Source/core/dom/Element.cpp?sq=package:chromium&l=2970
[3] https://jsfiddle.net/c02ux411/14/
[4] https://cs.chromium.org/chromium/src/third_party/WebKit/Source/core/editing/FrameSelection.cpp?gsn=SetSelection&l=289
[5] https://github.com/w3c/editing/issues


Thank you very much for the detailed answer - I really appreciate it, especially the part with the code!

I'm aware of the IME specifics so I can agree on the usage of input event.

As far as about the setSelection() usage and calling the focus, after that, I still have some doubts. In my case when the setSelection() method is called, the input is already on focus. If I execute it for a second time after selection takes place, then still the input is not scrolled to the caret position. Here (https://jsfiddle.net/Lipata/x966r76n/) is the sample.

I've already logged an issue in the W3C repo (https://github.com/w3c/editing/issues/173).

Best regards,
Nikolay Alipiev



Hi, guys.

As you suggested I have logged a bug (first to w3c (https://github.com/w3c/editing/issues/173) and then whatwg (https://github.com/whatwg/html/issues/3694#event-1632501344)). You can see the answer from @domenic in the whatwg/html repo, and tell me what you think. Do you think that this is something you need to implement, or there are reasons that it cannot be implemented.

Thank you in advance!
Nikolay Alipiev

Sign in to add a comment