Auto merge of #19358 - jonleighton:issue-19171-3, r=KiChjang

Move selection to end when textarea value is assigned

Issue #19171

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19358)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-11-25 16:10:41 -06:00 committed by GitHub
commit 3f0ccd0fef
8 changed files with 59 additions and 72 deletions

View file

@ -542604,7 +542604,7 @@
"testharness"
],
"html/semantics/forms/textfieldselection/selection-value-interactions.html": [
"c568d7fe10cb4c2071b5d38530ad601988a789ea",
"39fe9646bbc2741e9bd3296d4e01513c99106151",
"testharness"
],
"html/semantics/forms/textfieldselection/selection.html": [

View file

@ -1,35 +0,0 @@
[selection-start-end.html]
type: testharness
[Setting selectionStart to a value larger than selectionEnd should increase selectionEnd]
expected: FAIL
[Setting selectionEnd to a value smaller than selectionStart should decrease selectionStart]
expected: FAIL
[selectionStart edge-case values]
expected: FAIL
[Initial .value set on textarea-appended should set selectionStart to end of value]
expected: FAIL
[Initial .value set on textarea-not-appended should set selectionStart to end of value]
expected: FAIL
[Initial .value set on textarea-appended-prefocused should set selectionStart to end of value]
expected: FAIL
[Initial .value set on textarea-not-appended-prefocused should set selectionStart to end of value]
expected: FAIL
[Initial .value set on textarea-appended should set selectionEnd to end of value]
expected: FAIL
[Initial .value set on textarea-not-appended should set selectionEnd to end of value]
expected: FAIL
[Initial .value set on textarea-appended-prefocused should set selectionEnd to end of value]
expected: FAIL
[Initial .value set on textarea-not-appended-prefocused should set selectionEnd to end of value]
expected: FAIL

View file

@ -36,15 +36,9 @@
[test SelectionStart offset for textarea that is appended]
expected: FAIL
[test SelectionStart offset for textarea that is not appended]
expected: FAIL
[test SelectionEnd offset for input that is appended]
expected: FAIL
[test SelectionEnd offset for textarea that is appended]
expected: FAIL
[test SelectionEnd offset for textarea that is not appended]
expected: FAIL

View file

@ -1,17 +1,8 @@
[value-defaultValue-textContent.html]
type: testharness
[defaultValue and value treat CRLF differently]
expected: FAIL
[tests for the value setter]
expected: FAIL
[defaultValue and value are affected by textContent in combination with appending a DocumentFragment]
expected: FAIL
[defaultValue and value reflect child text content, not textContent]
expected: FAIL
[value normalizes CRLF even spread over multiple text nodes]
expected: FAIL

View file

@ -97,22 +97,31 @@ for (var tag of ['input', 'textarea']) {
var el = document.createElement(tag);
document.body.appendChild(el);
this.add_cleanup(() => el.remove());
el.value = "";
assert_equals(el.selectionStart, el.value.length,
"element.selectionStart should be value.length");
assert_equals(el.selectionEnd, el.value.length,
"element.selectionEnd should be value.length");
el.value = "foo";
assert_equals(el.selectionStart, el.value.length,
"element.selectionStart should be value.length");
assert_equals(el.selectionEnd, el.value.length,
"element.selectionEnd should be value.length");
el.value = "foobar";
assert_equals(el.selectionStart, el.value.length,
"element.selectionStart should be value.length");
assert_equals(el.selectionEnd, el.value.length,
"element.selectionEnd should be value.length");
}, `selection is always collapsed to the end after setting values on ${tag}`);
for (let val of ["", "foo", "foobar"]) {
el.value = val;
assert_equals(el.selectionStart, val.length,
"element.selectionStart should be value.length");
assert_equals(el.selectionEnd, val.length,
"element.selectionEnd should be value.length");
}
}, `selection is collapsed to the end after changing values on ${tag}`);
test(function() {
var el = document.createElement(tag);
document.body.appendChild(el);
this.add_cleanup(() => el.remove());
el.value = "foobar"
el.selectionStart = 2
el.selectionEnd = 4
el.value = "foobar"
assert_equals(el.selectionStart, 2,
"element.selectionStart should be unchanged");
assert_equals(el.selectionEnd, 4,
"element.selectionEnd should be unchanged");
}, `selection is not collapsed to the end when value is set to its existing value on ${tag}`);
}
</script>