Fix IME position with fullwidth chars in search

This commit is contained in:
Christian Duerr 2020-09-25 00:21:21 +00:00 committed by GitHub
parent 9a62f47292
commit 085cc35b14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -43,6 +43,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Pasting into clients only supporting `UTF8_STRING` mime type on Wayland
- Crash when copying/pasting with neither pointer nor keyboard focus on Wayland
- Crash due to fd leak on Wayland
- IME window position with fullwidth characters in the search bar
## 0.5.0

View File

@ -598,7 +598,7 @@ impl Display {
self.draw_search(config, &size_info, message_bar_lines, &search_text);
// Compute IME position.
Point::new(size_info.lines() - 1, Column(search_text.len() - 1))
Point::new(size_info.lines() - 1, Column(search_text.chars().count() - 1))
},
None => cursor_point,
};
@ -640,10 +640,11 @@ impl Display {
// Truncate beginning of the search regex if it exceeds the viewport width.
let num_cols = size_info.cols().0;
let label_len = search_label.len();
let regex_len = formatted_regex.len();
let label_len = search_label.chars().count();
let regex_len = formatted_regex.chars().count();
let truncate_len = min((regex_len + label_len).saturating_sub(num_cols), regex_len);
let truncated_regex = &formatted_regex[truncate_len..];
let index = formatted_regex.char_indices().nth(truncate_len).map(|(i, _c)| i).unwrap_or(0);
let truncated_regex = &formatted_regex[index..];
// Add search label to the beginning of the search regex.
let mut bar_text = format!("{}{}", search_label, truncated_regex);