-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src/editor.rc: Find in row.chars instead of row.render #23
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This seems to fix the issue.
However, the "match segment" highlighting needs to be fixed, see my comment below.
src/editor.rs
Outdated
@@ -132,6 +132,12 @@ fn format_size(n: u64) -> String { | |||
format!("{:.2$}{}B", q as f32 + r as f32 / 1024., prefix, p = if *prefix == "" { 0 } else { 2 }) | |||
} | |||
|
|||
/// Slice_find returns the index of `needle` in slice `s` if `needle` is a subslice of `s`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Pedantic clippy warning: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
/// Slice_find returns the index of `needle` in slice `s` if `needle` is a subslice of `s`, | |
/// `slice_find` returns the index of `needle` in slice `s` if `needle` is a subslice of `s`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, will fix that.
src/editor.rs
Outdated
/// Slice_find returns the index of `needle` in slice `s` if `needle` is a subslice of `s`, | ||
/// otherwise returns `None`. | ||
fn slice_find<T: PartialEq>(s: &[T], needle: &[T]) -> Option<usize> { | ||
(0..s.len()).filter(|&i| s[i..].starts_with(needle)).next() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small optimization: I think the upper bound can be (s.len() + 1).saturating_sub(needle.len())
(i.e. i
cannot be valid if i + needle.len() > s.len()
)
Also, you can replace _.filter(_).next()
with _.find(_)
(see this clippy warning)
src/editor.rs
Outdated
// Try to reset the column offset; if the match is after the offset, this | ||
// will be updated in self.scroll() so that the result is visible | ||
self.cursor.coff = 0; | ||
row.match_segment = Some(rx..rx + query.len()); | ||
row.match_segment = Some(cx..cx + query.len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
match_segment
contains a slice that represents the index in row.render
, not row.chars
.
If your buffer contains a
<TAB>
b
and you search for b
, b
should be highlighted, which is not the case here.
I believe this should work:
row.match_segment = Some(cx..cx + query.len()); | |
let rx = row.cx2rx[cx]; | |
row.match_segment = Some(rx..rx + query.len()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
This should be able to fix #19