Skip to content

Commit

Permalink
fixed wrong fuzzy-find highlight in long str (#1731)
Browse files Browse the repository at this point in the history
* fixed wrong highlight in long str
* support multibyte characters
  • Loading branch information
UUGTech authored Jul 6, 2023
1 parent 5c98e2f commit b4450f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixes
* fix commit dialog char count for multibyte characters ([#1726](https://github.com/extrawurst/gitui/issues/1726))
* fix wrong hit highlighting in fuzzy find popup [[@UUGTech](https://github.com/UUGTech)] ([#1731](https://github.com/extrawurst/gitui/pull/1731))

## [0.23.0] - 2022-06-19

Expand Down
58 changes: 33 additions & 25 deletions src/components/fuzzy_find_popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use ratatui::{
Frame,
};
use std::borrow::Cow;
use unicode_segmentation::UnicodeSegmentation;

pub struct FuzzyFindPopup {
queue: Queue,
Expand Down Expand Up @@ -237,31 +238,38 @@ impl DrawableComponent for FuzzyFindPopup {
let height = usize::from(chunks[1].height);
let width = usize::from(chunks[1].width);

let items = self.filtered.iter().take(height).map(
|(idx, indicies)| {
let selected = self
.selected_index
.map_or(false, |index| index == *idx);
let full_text = trim_length_left(
&self.contents[*idx],
width,
);
Line::from(
full_text
.char_indices()
.map(|(c_idx, c)| {
Span::styled(
Cow::from(c.to_string()),
self.theme.text(
selected,
indicies.contains(&c_idx),
),
)
})
.collect::<Vec<_>>(),
)
},
);
let items =
self.filtered.iter().take(height).map(
|(idx, indicies)| {
let selected = self
.selected_index
.map_or(false, |index| index == *idx);
let full_text = trim_length_left(
&self.contents[*idx],
width,
);
let trim_length = self.contents[*idx]
.graphemes(true)
.count() - full_text
.graphemes(true)
.count();
Line::from(
full_text
.graphemes(true)
.enumerate()
.map(|(c_idx, c)| {
Span::styled(
Cow::from(c.to_string()),
self.theme.text(
selected,
indicies.contains(&(c_idx + trim_length)),
),
)
})
.collect::<Vec<_>>(),
)
},
);

ui::draw_list_block(
f,
Expand Down

0 comments on commit b4450f9

Please sign in to comment.