Correct default selectionStart and selectionEnd

This commit is contained in:
paavininanda 2018-02-21 01:29:33 +05:30
parent b517410a34
commit 87e7b1ee7a
7 changed files with 58 additions and 26 deletions

View file

@ -494,10 +494,11 @@ fn test_textinput_set_content() {
assert_eq!(textinput.edit_point().line, 0);
assert_eq!(textinput.edit_point().index, 0);
textinput.adjust_horizontal(3, Selection::Selected);
assert_eq!(textinput.edit_point().line, 0);
assert_eq!(textinput.edit_point().index, 3);
textinput.set_content(DOMString::from("de"), true);
textinput.set_content(DOMString::from("de"));
assert_eq!(textinput.get_content(), "de");
assert_eq!(textinput.edit_point().line, 0);
assert_eq!(textinput.edit_point().index, 2);
@ -634,6 +635,10 @@ fn test_textinput_unicode_handling() {
fn test_selection_bounds() {
let mut textinput = text_input(Lines::Single, "abcdef");
assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_origin_or_edit_point());
assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_start());
assert_eq!(TextPoint { line: 0, index: 0 }, textinput.selection_end());
textinput.set_selection_range(2, 5, SelectionDirection::Forward);
assert_eq!(TextPoint { line: 0, index: 2 }, textinput.selection_origin_or_edit_point());
assert_eq!(TextPoint { line: 0, index: 2 }, textinput.selection_start());

View file

@ -330871,6 +330871,12 @@
{}
]
],
"html/semantics/forms/textfieldselection/defaultSelection.html": [
[
"/html/semantics/forms/textfieldselection/defaultSelection.html",
{}
]
],
"html/semantics/forms/textfieldselection/select-event.html": [
[
"/html/semantics/forms/textfieldselection/select-event.html",

View file

@ -1,4 +0,0 @@
[setSelectionRange.html]
[setSelectionRange on line boundaries]
expected: FAIL

View file

@ -0,0 +1,28 @@
<!doctype html>
<meta charset="utf-8">
<title></title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<textarea>foo</textarea>
<input type="text" value="foo"></input>
<script>
for (let el of [document.querySelector("textarea"), document.querySelector("input")]) {
test(function() {
assert_equals(el.selectionStart, 0);
assert_equals(el.selectionEnd, 0);
}, `Default selectionStart and selectionEnd for ${el}`);
test(function() {
el.value="foo";
assert_equals(el.selectionStart, 0);
assert_equals(el.selectionEnd, 0);
}, `selectionStart and selectionEnd do not change when same value set again for ${el}`);
test(function() {
el.value="Foo";
assert_equals(el.selectionStart, 3);
assert_equals(el.selectionEnd, 3);
}, `selectionStart and selectionEnd change when value changed to upper case for ${el}`);
}
</script>