Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

textinput.rs replace_selection now slices wrt bytes rather than chars #20208

Closed
wants to merge 6 commits into from
Prev

cleaned code, added testcase

  • Loading branch information
sarkhanbayramli committed Mar 12, 2018
commit f08850b9ab7fdf393f3cb337a940809ef0567f96
@@ -379,11 +379,11 @@ impl<T: ClipboardProvider> TextInput<T> {
} else {
usize::MAX
};

// If len_of_first_n_code_units returns None, we are over allowed_to_insert_count
let last_char_index_opt = len_of_first_n_code_units(&*insert, allowed_to_insert_count);
self.clear_selection();
if last_char_index_opt.is_some() {
if last_char_index_opt.is_some() {
let chars_to_insert = &insert[..last_char_index_opt.unwrap()];

let new_lines = {
@@ -420,7 +420,7 @@ impl<T: ClipboardProvider> TextInput<T> {
self.lines = new_lines;
}
self.assert_ok_selection();

}

/// Return the length in UTF-8 bytes of the current line under the editing point.
@@ -619,6 +619,9 @@ fn test_textinput_set_selection_with_direction() {
assert_eq!(textinput.selection_origin().unwrap().line, 0);
assert_eq!(textinput.selection_origin().unwrap().index, 0);

textinput = text_input(Lines::Single, "€");
textinput.set_selection_range(1, 1, SelectionDirection::Forward);
assert_eq!(textinput.edit_point().index, 2);
}

#[test]
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.