diff options
author | Christian Duerr <contact@christianduerr.com> | 2020-09-25 00:21:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-25 00:21:21 +0000 |
commit | 085cc35b14e7c835e1a9add408b45da583959a6c (patch) | |
tree | 1e6fd88456c55585ed24cb453549cce4e1c7ef92 | |
parent | 9a62f4729215a7ca4a69cf54df8663ff84c27ec2 (diff) | |
download | alacritty-085cc35b14e7c835e1a9add408b45da583959a6c.tar.gz alacritty-085cc35b14e7c835e1a9add408b45da583959a6c.zip |
Fix IME position with fullwidth chars in search
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | alacritty/src/display.rs | 9 |
2 files changed, 6 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index bcd8f69b..d7c7603e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/alacritty/src/display.rs b/alacritty/src/display.rs index 00bfd83a..ca5bfe34 100644 --- a/alacritty/src/display.rs +++ b/alacritty/src/display.rs @@ -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); |