Skip to content

Commit

Permalink
Reduce unicode_column_width call
Browse files Browse the repository at this point in the history
  • Loading branch information
kumattau committed May 7, 2024
1 parent 1163d17 commit 6a3f3da
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions wezterm-gui/src/termwindow/render/screen_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,32 @@ impl crate::TermWindow {
composing_text_width = unicode_column_width(text, None);

if let Some(attr) = attr {
// convert text and attr to selections
// convert SELECTED attr to selections
let mut selection = 0usize..0;
// iterate over byte end of each character in text
for (i, end) in text
for (j, end) in text
.char_indices()
.map(|(offset, _)| offset)
.chain([text.len()])
.enumerate()
.skip(1)
.take(attr.len())
.enumerate()
{
// update end to unicode width
let end = unicode_column_width(&text[..end], None);
if attr[i].contains(ComposingAttribute::SELECTED) {
selection.end = end;
}
// add non-empty selection and prepare next selection
if i + 1 == attr.len() || !attr[i].contains(ComposingAttribute::SELECTED) {
if !selection.is_empty() {
composing_selections.push(selection);
let i = j - 1;
// check last character or SELECTED switch
if j == attr.len()
|| (attr[i] ^ attr[j]).contains(ComposingAttribute::SELECTED)
{
// update end to unicode width
let end = unicode_column_width(&text[..end], None);
// add selection to selections if attr[i] is end of SELECTED
if attr[i].contains(ComposingAttribute::SELECTED) {
selection.end = end;
if !selection.is_empty() {
composing_selections.push(selection);
}
}
// prepare selection for next SELECTED or start of SELECTED
selection = end..end;
}
}
Expand Down

0 comments on commit 6a3f3da

Please sign in to comment.