mirror of
https://github.com/servo/servo.git
synced 2025-08-12 00:45:33 +01:00
Auto merge of #10350 - mbrubeck:selection-chars, r=SimonSapin
Fix some char/byte bugs in textinput Fixes #9569. r? @SimonSapin or @Ms2ger <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10350) <!-- Reviewable:end -->
This commit is contained in:
commit
c0bfcc5155
3 changed files with 167 additions and 35 deletions
|
@ -117,6 +117,55 @@ fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_
|
|||
assert_eq!(textinput.get_content(), "atooe");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_line_textinput_with_max_length_multibyte() {
|
||||
let mut textinput = TextInput::new(
|
||||
Lines::Single,
|
||||
DOMString::from(""),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(2)
|
||||
);
|
||||
|
||||
textinput.insert_char('á');
|
||||
assert_eq!(textinput.get_content(), "á");
|
||||
textinput.insert_char('é');
|
||||
assert_eq!(textinput.get_content(), "áé");
|
||||
textinput.insert_char('i');
|
||||
assert_eq!(textinput.get_content(), "áé");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_line_textinput_with_max_length_multi_code_unit() {
|
||||
let mut textinput = TextInput::new(
|
||||
Lines::Single,
|
||||
DOMString::from(""),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(3)
|
||||
);
|
||||
|
||||
textinput.insert_char('\u{10437}');
|
||||
assert_eq!(textinput.get_content(), "\u{10437}");
|
||||
textinput.insert_char('\u{10437}');
|
||||
assert_eq!(textinput.get_content(), "\u{10437}");
|
||||
textinput.insert_char('x');
|
||||
assert_eq!(textinput.get_content(), "\u{10437}x");
|
||||
textinput.insert_char('x');
|
||||
assert_eq!(textinput.get_content(), "\u{10437}x");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_line_textinput_with_max_length_inside_char() {
|
||||
let mut textinput = TextInput::new(
|
||||
Lines::Single,
|
||||
DOMString::from("\u{10437}"),
|
||||
DummyClipboardContext::new(""),
|
||||
Some(1)
|
||||
);
|
||||
|
||||
textinput.insert_char('x');
|
||||
assert_eq!(textinput.get_content(), "\u{10437}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_single_line_textinput_with_max_length_doesnt_allow_appending_characters_after_max_length_is_reached() {
|
||||
let mut textinput = TextInput::new(
|
||||
|
@ -206,6 +255,15 @@ fn test_textinput_replace_selection() {
|
|||
assert_eq!(textinput.get_content(), "abxyzefg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_textinput_replace_selection_multibyte_char() {
|
||||
let mut textinput = text_input(Lines::Single, "é");
|
||||
textinput.adjust_horizontal_by_one(Direction::Forward, Selection::Selected);
|
||||
|
||||
textinput.replace_selection(DOMString::from("e"));
|
||||
assert_eq!(textinput.get_content(), "e");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_textinput_current_line_length() {
|
||||
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
|
||||
|
@ -235,6 +293,19 @@ fn test_textinput_adjust_vertical() {
|
|||
assert_eq!(textinput.edit_point.index, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_textinput_adjust_vertical_multibyte() {
|
||||
let mut textinput = text_input(Lines::Multiple, "áé\nae");
|
||||
|
||||
textinput.adjust_horizontal_by_one(Direction::Forward, Selection::NotSelected);
|
||||
assert_eq!(textinput.edit_point.line, 0);
|
||||
assert_eq!(textinput.edit_point.index, 2);
|
||||
|
||||
textinput.adjust_vertical(1, Selection::NotSelected);
|
||||
assert_eq!(textinput.edit_point.line, 1);
|
||||
assert_eq!(textinput.edit_point.index, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_textinput_adjust_horizontal() {
|
||||
let mut textinput = text_input(Lines::Multiple, "abc\nde\nf");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue