Skip to content
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

Merged
merged 1 commit into from
Mar 29, 2020
Merged

src/editor.rc: Find in row.chars instead of row.render #23

merged 1 commit into from
Mar 29, 2020

Conversation

ldang0
Copy link
Contributor

@ldang0 ldang0 commented Mar 26, 2020

This should be able to fix #19

Copy link
Owner

@ilai-deutel ilai-deutel left a 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`,
Copy link
Owner

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

Suggested change
/// 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`,

Copy link
Contributor Author

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()
Copy link
Owner

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());
Copy link
Owner

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:

Suggested change
row.match_segment = Some(cx..cx + query.len());
let rx = row.cx2rx[cx];
row.match_segment = Some(rx..rx + query.len());

Copy link
Owner

@ilai-deutel ilai-deutel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Find within row.chars, not row.render
2 participants