mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 08:58:21 +00:00
fixed wrong fuzzy-find highlight in long str (#1731)
* fixed wrong highlight in long str * support multibyte characters
This commit is contained in:
parent
5c98e2fe76
commit
b4450f9bc3
2 changed files with 34 additions and 25 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use ratatui::{
|
|||
Frame,
|
||||
};
|
||||
use std::borrow::Cow;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
pub struct FuzzyFindPopup {
|
||||
queue: Queue,
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue