-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not change input/textarea text selection for the same value #2437
Conversation
8408edc
to
ef56a40
Compare
source
Outdated
must set the element's <code data-x="attr-input-value">value</code> attribute to the new | ||
value.</p> | ||
<p>On getting, if the element has a <code data-x="attr-input-value">value</code> content | ||
attribute, return that attribute's value; otherwise, it return the empty string.</p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/it return/return/?
source
Outdated
perform the following steps:</p> | ||
|
||
<ol> | ||
<li><p>Let <var>oldValue</var> be this element's <span |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be value, raw value, or API value?
Why did we pick value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
value and API value seem to be equivalent as both normalize line endings in some way. I went with value because it matched the corresponding text for input. And I picked between those two since it seemed like changing the line endings should not impact the selection since it's not observable during submission or through the API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I recall correctly, API value is the one that is reasonably cheap to produce, while "value" is the one that takes a bunch of processing. But I could be getting them backwards! This is for textarea; for input the two are identical, iirc... It's really worth checking what UAs actually do here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the purposes of comparing old and new, API value and value will be identical. Raw value will have unnormalized line endings. Chrome at least does not treat \r\n
different from \n
when determining whether to reset the selection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the purposes of comparing old and new, API value and value will be identical.
I'm not sure I follow. value
is affected by the wrap
attribute; API value
is not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and both oldValue and the new value will be affected in the same way, if they are identical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but if they are not, the value
can still end up the same even if the API value
is different.
This would require every single browser to change behavior, right? And they're all interoperable right now? I'm somewhat worried about how web-compatible this change will be.... |
No, they're not really interoperable, according to the tests at http://w3c-test.org/submissions/5147/html/semantics/forms/textfieldselection/selection-after-content-change.html. From what I see in the tests:
|
OK, correction. I thought things were interoperable in terms of cursor position behavior for setting .value when an input actually has focus (or possibly just has a CSS box). I agree that the out-of-document cases are all sorts of weird. For one thing, they're incredibly buggy in Firefox unless you're testing a current nightly. One other note on the tests: they assert that selection direction becomes "none" in various cases, but it's not clear to me that they can in fact do that. That's because the platform may not support selections with direction "none" at all. See the bits in https://html.spec.whatwg.org/multipage/forms.html#set-the-selection-range It looks like some other parts of the spec (e.g. the |
I'll add focus to the test matrix, although I think it'd be ideal if we didn't branch on that. Certainly if an element has a CSS box there is no interop, e.g. Chrome has no-op behavior for textarea whereas Firefox does not (Edge might or might not). But I guess if testing reveals nobody has no-op behavior for focused inputs we should probably code that in.
Oh dear, good point, hmm. For the tests, I'll loosen it to allow either forward or none. I guess the spec will need some kind of generic set selection direction thingy. One weird thing is that Chrome sets a selection direction of none for input, but not textarea (on Windows). Is that reasonable, or should we disallow that? @tkent-google |
This fixes the issue noted in #2437 (comment) where the spec sometimes assumed it was OK to set the selection direction to none, even though not all platforms support this. It introduces a new concept, "set the selection direction", which will convert "none" to "forward" as appropriate. This commit also makes a couple editorial tweaks: * Replaces the italicized selection direction states with simple strings, which allows us to avoid a switch statement to translate between them. * Splits out getter and setters in <input> and <textarea>'s value IDL attribute definitions, and gives the setters a proper numbered list.
ef56a40
to
7c751c9
Compare
I've updated this PR to be on top of #2439, which should make the important changes clearer if you just look at the second commit. I've also updated the tests. There doesn't seem to be a lot of interop around the failing test cases---even when different browsers fail the same test, they often do so in different ways. So I think the plan in this PR is still pretty good. |
This fixes the issue noted in #2437 (comment) where the spec sometimes assumed it was OK to set the selection direction to none, even though not all platforms support this. It introduces a new concept, "set the selection direction", which will convert "none" to "forward" as appropriate. This commit also makes a couple editorial tweaks: * Replaces the italicized selection direction states with simple strings, which allows us to avoid a switch statement to translate between them. * Splits out getter and setters in <input> and <textarea>'s value IDL attribute definitions, and gives the setters a proper numbered list.
This fixes the issue noted in #2437 (comment) where the spec sometimes assumed it was OK to set the selection direction to none, even though not all platforms support this. It introduces a new concept, "set the selection direction", which will convert "none" to "forward" as appropriate. This commit also makes a couple editorial tweaks: * Replaces the italicized selection direction states with simple strings, which allows us to avoid a switch statement to translate between them. * Splits out getter and setters in <input> and <textarea>'s value IDL attribute definitions, and gives the setters a proper numbered list.
Definitely we shouldn't set "none" on platforms without "none". |
7c751c9
to
ced0b03
Compare
@bzbarsky are you still worried about compat for this, given the test results? As I said, there doesn't seem to be a lot of interop around the failing test cases seen in web-platform-tests/wpt#5147, so I am not worried myself. @tkent-google would you mind doing a review to make sure this matches your intent when proposing #2412? You may also want to review web-platform-tests/wpt#5147. |
Yeah, I'm still somewhat worried about compat. I'm not an expert on this stuff, though. @smaug---- and @masayuki-nakano should probably have a look at this. |
I have no idea what accident could be caused by the behavior. I like doing nothing if setting value is same as current value better because some web apps may do such redundant thing for keeping their implementation simpler but it might cause odd undo transaction or killing some IME feature. For example, that may cause browser notifying IME of text change and selection change of focused editor. Then, IME may discard the last commit information for undoing. And I have a question, if setting same value should do nothing, should active composition not be committed if there is? Firefox ignores setting same value when there is composition, to protect the composition: |
The spec change lgtm. |
I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1357206 on Gecko. |
Oh, oops, I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1357204. Feel free to dupe one or the other... Other bugs: |
Ah, I think we basically mid-aired on filing this. ;) |
@domenic I tried implementing it and ran into something that's unclear. See web-platform-tests/wpt#5147 (comment) |
This is a follow-up to #2437, which introduced the value comparison and its impact on selection. See web-platform-tests/wpt#5147 (comment).
This is a follow-up to #2437, which introduced the value comparison and its impact on selection. See web-platform-tests/wpt#5147 (comment).
This is a follow-up to whatwg#2437, which introduced the value comparison and its impact on selection. See web-platform-tests/wpt#5147 (comment).
This is a follow-up to whatwg#2437, which introduced the value comparison and its impact on selection. See web-platform-tests/wpt#5147 (comment).
This fixes the issue noted in whatwg#2437 (comment) where the spec sometimes assumed it was OK to set the selection direction to none, even though not all platforms support this. It introduces a new concept, "set the selection direction", which will convert "none" to "forward" as appropriate. This commit also makes a couple editorial tweaks: * Replaces the italicized selection direction states with simple strings, which allows us to avoid a switch statement to translate between them. * Splits out getter and setters in <input> and <textarea>'s value IDL attribute definitions, and gives the setters a proper numbered list.
This is a follow-up to whatwg#2437, which introduced the value comparison and its impact on selection. See web-platform-tests/wpt#5147 (comment).
Per the test case included as an example in the spec, this is more in line with browser behavior, and makes more sense. A similar conclusion was reached on related matters in whatwg#2424, and also in whatwg#2437.
Fixes #2412.
This also makes slight editorial changes to nearby setter/getter pairs to separate their steps and stop saying "it must".
Tests: web-platform-tests/wpt#5147
/cc @bzbarsky @tkent-google @rniwa