Skip to content

Commit

Permalink
Fix indexing on non-matching tail substring
Browse files Browse the repository at this point in the history
  • Loading branch information
l4l committed Dec 27, 2020
1 parent b3fca99 commit b990057
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/draw/list_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ where
let match_ranges = item.match_mask.unwrap_or(&empty);

fn substr<'a, 'b: 'a>(x: &'b str, r: &Range<usize>) -> &'a str {
assert!(r.end <= x.chars().count());
debug_assert!(r.end <= x.chars().count());
let start = x
.char_indices()
.nth(r.start)
Expand Down Expand Up @@ -202,14 +202,9 @@ where
(draw_substr!(&range, pos, color), range.end)
});

dt.draw_text(
&self.params.font,
font_size,
substr(item.name, &(idx..item.name.len())),
pos,
&Source::Solid(color),
&draw_opts,
);
let tail_str = substr(item.name, &(idx..item.name.chars().count()));
let color = Source::Solid(color);
dt.draw_text(&font, font_size, tail_str, pos, &color, &draw_opts);
} else {
dt.draw_text(
&self.params.font,
Expand Down

0 comments on commit b990057

Please sign in to comment.