Skip to content

Search: support multiple matches#532

Open
rtczza wants to merge 3 commits into
ilai-deutel:masterfrom
rtczza:master
Open

Search: support multiple matches#532
rtczza wants to merge 3 commits into
ilai-deutel:masterfrom
rtczza:master

Conversation

@rtczza
Copy link
Copy Markdown

@rtczza rtczza commented Dec 2, 2025

fix: #487

@coveralls
Copy link
Copy Markdown

coveralls commented Dec 2, 2025

Pull Request Test Coverage Report for Build 21161689652

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 65 of 65 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+3.4%) to 71.596%

Totals Coverage Status
Change from base Build 19849836628: 3.4%
Covered Lines: 915
Relevant Lines: 1278

💛 - Coveralls

Copy link
Copy Markdown
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 very much for your contribution!

  • Please make sure the PR checks pass, it seems like there a formatting issue (cargo +nightly fmt should fix it)
  • Could you please add a test for the new feature at the bottom of editor.rs? Current coverage for kibi is unfortunately not comprehensive, but for new features having tests would be great

Comment thread src/editor.rs Outdated
let current = last_match.unwrap_or_else(|| num_rows.saturating_sub(1));
// 清除所有行的 match_segments
for row in &mut self.rows {
row.match_segments.clear();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Could this be moved to the for loop below, to save 2 lines of code?

Comment thread src/editor.rs Outdated
row.match_segment = Some(rx..rx + query.len());
return Some(current);
let current = last_match.unwrap_or_else(|| num_rows.saturating_sub(1));
// 清除所有行的 match_segments
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please keep all the comments in English, thanks :)

(and similarly below)

Comment thread src/editor.rs
}
let mut found_row = None;
for idx in 0..num_rows {
let i = (current + if forward { 1 } else { num_rows - 1 } + idx) % num_rows;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I tried running the code, searching backwards (pressing up arrow key while the search prompt is open) seems to be broken now

Comment thread src/row.rs
/// If not `None`, the range that is currently matched during a FIND
/// operation.
pub match_segment: Option<std::ops::Range<usize>>,
pub match_segments: Vec<std::ops::Range<usize>>,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think I would rather keep the current behavior of only highlighting one match at a time, otherwise we can't tell visually which position we matched (where the cursor will be after we press enter)
This way you can also return early in the loop in editor, without having to search through the entire file at once

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

If "keep the current behavior of only highlighting one match at a time", then this PR can be turned off. Hahaha
If you want to support multi-highlight display, I can modify the above code according to your suggestions.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

For #487 the main concern is being able to have multiple matches per line, which is not currently supported, but your PR solves.

So we could have something like:

1 │𝐇𝐞𝐥lo Hello World
~ │
Search (Use ESC/Arrows/Enter): Hel

and when pressing the right arrow, the match would become

1 │Hello 𝐇𝐞𝐥lo World
~ │
Search (Use ESC/Arrows/Enter): Hel

I think highlighting every match would be valuable, but we need to be able to differentiate the current match (where the cursor will be after pressing Enter) versus all the other matches. I think the current match could keep the current styling; maybe the other ones could be underlined instead (ANSI code for underline: \x1b[4m). What do you think?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Your idea is great. I understand what you mean. I'll try to implement it during this period of time. I might not have time these two days.

@ilai-deutel
Copy link
Copy Markdown
Owner

@all-contributors Please add @rtczza for code.

@allcontributors
Copy link
Copy Markdown
Contributor

@ilai-deutel

I've put up a pull request to add @rtczza! 🎉

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.

Search: support multiple matches per line

3 participants