mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Find the correct column index in adjust_vertical
This commit is contained in:
parent
e17ed2e6b0
commit
29fb3f1150
2 changed files with 17 additions and 1 deletions
|
@ -301,8 +301,11 @@ impl<T: ClipboardProvider> TextInput<T> {
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
let col = self.lines[self.edit_point.line][..self.edit_point.index].chars().count();
|
||||
|
||||
self.edit_point.line = target_line as usize;
|
||||
self.edit_point.index = min(self.current_line_length(), self.edit_point.index);
|
||||
self.edit_point.index = len_of_first_n_chars(&self.lines[self.edit_point.line], col);
|
||||
}
|
||||
|
||||
/// Adjust the editing point position by a given number of bytes. If the adjustment
|
||||
|
|
|
@ -244,6 +244,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