Bug 191255 - Setting input's value to the same value moves caret at end of input
Summary: Setting input's value to the same value moves caret at end of input
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: HTML Editing (show other bugs)
Version: Safari 12
Hardware: Unspecified macOS 10.14
: P2 Normal
Assignee: Joonghun Park
URL: https://jsfiddle.net/foavjy3n/2/
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-11-05 02:37 PST by Giovanni Piller Cottrer
Modified: 2021-09-22 17:42 PDT (History)
15 users (show)

See Also:


Attachments
Bug reproduction (363.41 KB, video/quicktime)
2018-11-05 02:37 PST, Giovanni Piller Cottrer
no flags Details
Patch (3.34 KB, patch)
2018-11-19 03:31 PST, Giovanni Piller Cottrer
no flags Details | Formatted Diff | Diff
Archive of layout-test-results from ews102 for mac-sierra (2.51 MB, application/zip)
2018-11-19 04:32 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews107 for mac-sierra-wk2 (2.95 MB, application/zip)
2018-11-19 04:44 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews112 for mac-sierra (2.25 MB, application/zip)
2018-11-19 05:23 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews203 for win-future (12.81 MB, application/zip)
2018-11-19 05:23 PST, EWS Watchlist
no flags Details
Archive of layout-test-results from ews123 for ios-simulator-wk2 (17.44 MB, application/zip)
2018-11-19 05:25 PST, EWS Watchlist
no flags Details
Submit patch to check layout test result (1.89 KB, patch)
2021-09-18 07:05 PDT, Joonghun Park
no flags Details | Formatted Diff | Diff
patch to check layout test result (2.00 KB, patch)
2021-09-18 17:23 PDT, Joonghun Park
no flags Details | Formatted Diff | Diff
Patch (9.49 KB, patch)
2021-09-18 18:13 PDT, Joonghun Park
no flags Details | Formatted Diff | Diff
Patch For Landing (9.45 KB, patch)
2021-09-22 17:06 PDT, Joonghun Park
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Giovanni Piller Cottrer 2018-11-05 02:37:21 PST
Created attachment 353841 [details]
Bug reproduction

Focusing at the beginning of an input, caret at position 0, then setting `input.value = input.value` will move caret position to the end of the input.

This is inconsistent with other browser's implementations (tested on Chrome 70.0.3538.77 and Firefox 63.0.1).
Also inconsistent with WebKit's <textarea> element, where setting `textarea.value = textarea.value` won't move the caret.

I've created a JSFiddle to give you an example. Also, attached a video with reproduction.

JSFiddle: https://jsfiddle.net/foavjy3n/2/ (code also pasted below)

/////////////////////////////////////////////

<main>
  <p>Start typing <strong>BEFORE</strong> "test".</p>
  <p>Focus will be moved at the end of the INPUT, while this won't happen for the TEXTAREA.</p>

  <div>
    <label for="input-text">Plain text input</label>
    <input id="input-text" type="text" value="test">
  </div>

  <div>
    <label for="textarea">Textarea</label>
    <textarea id="textarea">test</textarea>
  </div>
</main>

<script>
  function monitorValueFor(id) {
    const element = document.getElementById(id);

    element.addEventListener('input', ({ target }) => {
      target.value = target.value;
    });
  }

  monitorValueFor('input-text');
  monitorValueFor('textarea');
</script>
Comment 1 Giovanni Piller Cottrer 2018-11-19 03:31:04 PST
Created attachment 355262 [details]
Patch
Comment 2 Giovanni Piller Cottrer 2018-11-19 03:49:58 PST
Note: patch is supposed to do the same thing as HTMLTextAreaElement::setValueCommon (See lines 384 to 387 of HTMLTextAreaElement.cpp), which is why I used the same comment.
Comment 3 EWS Watchlist 2018-11-19 04:32:24 PST
Comment on attachment 355262 [details]
Patch

Attachment 355262 [details] did not pass mac-ews (mac):
Output: https://webkit-queues.webkit.org/results/10076909

New failing tests:
editing/input/setting-same-value-on-input-should-not-change-caret-position.html
imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-value-interactions.html
imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-after-content-change.html
fast/forms/range/range-set-attribute.html
fast/forms/number/number-validity-badinput.html
Comment 4 EWS Watchlist 2018-11-19 04:32:26 PST
Created attachment 355265 [details]
Archive of layout-test-results from ews102 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-ews.
Bot: ews102  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 5 EWS Watchlist 2018-11-19 04:44:12 PST
Comment on attachment 355262 [details]
Patch

Attachment 355262 [details] did not pass mac-wk2-ews (mac-wk2):
Output: https://webkit-queues.webkit.org/results/10076935

New failing tests:
fast/forms/number/number-validity-badinput.html
imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-value-interactions.html
imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-after-content-change.html
fast/forms/range/range-set-attribute.html
editing/input/setting-same-value-on-input-should-not-change-caret-position.html
Comment 6 EWS Watchlist 2018-11-19 04:44:14 PST
Created attachment 355267 [details]
Archive of layout-test-results from ews107 for mac-sierra-wk2

The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews.
Bot: ews107  Port: mac-sierra-wk2  Platform: Mac OS X 10.12.6
Comment 7 EWS Watchlist 2018-11-19 05:23:35 PST
Comment on attachment 355262 [details]
Patch

Attachment 355262 [details] did not pass mac-debug-ews (mac):
Output: https://webkit-queues.webkit.org/results/10077048

New failing tests:
editing/input/setting-same-value-on-input-should-not-change-caret-position.html
imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-value-interactions.html
imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-after-content-change.html
fast/forms/range/range-set-attribute.html
fast/forms/number/number-validity-badinput.html
Comment 8 EWS Watchlist 2018-11-19 05:23:37 PST
Created attachment 355269 [details]
Archive of layout-test-results from ews112 for mac-sierra

The attached test failures were seen while running run-webkit-tests on the mac-debug-ews.
Bot: ews112  Port: mac-sierra  Platform: Mac OS X 10.12.6
Comment 9 EWS Watchlist 2018-11-19 05:23:44 PST
Comment on attachment 355262 [details]
Patch

Attachment 355262 [details] did not pass win-ews (win):
Output: https://webkit-queues.webkit.org/results/10077129

New failing tests:
editing/input/setting-same-value-on-input-should-not-change-caret-position.html
fast/forms/number/number-l10n-input.html
fast/forms/range/range-set-attribute.html
fast/forms/number/number-validity-badinput.html
Comment 10 EWS Watchlist 2018-11-19 05:23:55 PST
Created attachment 355270 [details]
Archive of layout-test-results from ews203 for win-future

The attached test failures were seen while running run-webkit-tests on the win-ews.
Bot: ews203  Port: win-future  Platform: CYGWIN_NT-6.1-2.9.0-0.318-5-3-x86_64-64bit
Comment 11 EWS Watchlist 2018-11-19 05:25:06 PST
Comment on attachment 355262 [details]
Patch

Attachment 355262 [details] did not pass ios-sim-ews (ios-simulator-wk2):
Output: https://webkit-queues.webkit.org/results/10076946

New failing tests:
editing/input/setting-same-value-on-input-should-not-change-caret-position.html
imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-value-interactions.html
imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-after-content-change.html
fast/forms/range/range-set-attribute.html
fast/forms/number/number-validity-badinput.html
Comment 12 EWS Watchlist 2018-11-19 05:25:08 PST
Created attachment 355271 [details]
Archive of layout-test-results from ews123 for ios-simulator-wk2

The attached test failures were seen while running run-webkit-tests on the ios-sim-ews.
Bot: ews123  Port: ios-simulator-wk2  Platform: Mac OS X 10.13.6
Comment 13 Giovanni Piller Cottrer 2018-11-19 09:50:05 PST
Sorry for the broken patch. Next time I'll be more cautious.

Note: my patch (https://bugs.webkit.org/attachment.cgi?id=355262) is missing a -expected.txt file for the new test. I'm not going to submit a new one just for this, since it would trigger all the testing process.

-----------

I'll try to work a bit more on this, but it's clear that I'm missing something.

For example: I'm now thinking that the fix should be applied just to TextFieldInputType::setValue, but any approach I take leaves at least these 2 tests failing:

imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-value-interactions.html
imported/w3c/web-platform-tests/html/semantics/forms/textfieldselection/selection-after-content-change.html
Comment 14 Chris Dumez 2018-11-19 09:57:06 PST
Try to match the spec as closely as possible :
https://html.spec.whatwg.org/#dom-input-value

Your current patch seems to bypass work that we are supposed to do as per spec, only the cursor position change is supposed to be impacted.
Comment 15 Ryosuke Niwa 2018-11-19 13:59:18 PST
Comment on attachment 355262 [details]
Patch

r- due to the new test failures.
Comment 16 Joonghun Park 2021-09-18 07:05:33 PDT
Created attachment 438558 [details]
Submit patch to check layout test result
Comment 17 Joonghun Park 2021-09-18 17:23:07 PDT
Created attachment 438571 [details]
patch to check layout test result
Comment 18 Joonghun Park 2021-09-18 18:13:12 PDT
Created attachment 438574 [details]
Patch
Comment 19 Joonghun Park 2021-09-22 09:41:01 PDT
Could you please review this change? I think this patch is ready for review.
Comment 20 Simon Fraser (smfr) 2021-09-22 10:28:49 PDT
Comment on attachment 438574 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=438574&action=review

> Source/WebCore/ChangeLog:14
> +        Reviewed by NOBODY (OOPS!).

This line should go below the bug link (with a blank line in between).

> LayoutTests/imported/w3c/ChangeLog:14
> +        Reviewed by NOBODY (OOPS!).

Ditto
Comment 21 Joonghun Park 2021-09-22 16:57:36 PDT
Comment on attachment 438574 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=438574&action=review

>> Source/WebCore/ChangeLog:14
>> +        Reviewed by NOBODY (OOPS!).
> 
> This line should go below the bug link (with a blank line in between).

Ok, I will move this in the next patchset.

>> LayoutTests/imported/w3c/ChangeLog:14
>> +        Reviewed by NOBODY (OOPS!).
> 
> Ditto

Done.
Comment 22 Joonghun Park 2021-09-22 17:06:01 PDT
Created attachment 438993 [details]
Patch For Landing
Comment 23 EWS 2021-09-22 17:40:20 PDT
Committed r282898 (242026@main): <https://commits.webkit.org/242026@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 438993 [details].
Comment 24 Radar WebKit Bug Importer 2021-09-22 17:42:03 PDT
<rdar://problem/83425241>