Skip to content

Conversation

@useche
Copy link
Contributor

@useche useche commented Sep 14, 2024

This patch changes search_impl to calculate the index of the current match and the total matches in the search. It also adds a new option in the status line to show this information.

@Axlefublr
Copy link
Contributor

love this, was clearly missing

@kirawi kirawi added A-gui Area: Helix gui improvements A-command Area: Commands labels Sep 28, 2024
@david-crespo
Copy link
Contributor

Wonderful, I love this. No noticeable lag on an M1 Mac in a 21k line file with 56k matches for ". I think a cap on the number of matches would be fine — 99.9% of the time I would not be hitting the cap.

@useche useche force-pushed the search_position branch 4 times, most recently from e668b57 to 937a79d Compare October 6, 2024 19:25
@useche useche requested a review from archseer October 9, 2024 19:00
@Oyyko
Copy link

Oyyko commented Feb 23, 2025

Love it!

@rockboynton
Copy link
Contributor

Nice! This fills a very similar need to #12326, but for searches instead of selections

@david-crespo

This comment was marked as outdated.

@useche useche force-pushed the search_position branch from 36eb43e to daae1cf Compare May 16, 2025 01:47
useche added 2 commits May 15, 2025 18:56
This patch changes `search_impl` to calculate the index of the current
match and the total matches in the search. It also adds a new option in
the status line to show this information.
The new option `max-matches` can be set to `"none"` or an integer that
specifies that maximum number of matches. It's set by default to `100`.
@useche useche force-pushed the search_position branch from daae1cf to 0d894b5 Compare May 16, 2025 01:58
@useche
Copy link
Contributor Author

useche commented May 16, 2025

In case it helps anyone else, here are the conflict resolutions and compile fixes required to merge this into master locally.

diff --git a/book/src/editor.md b/book/src/editor.md
index 0000000000..71b273bb0f 100644
--- a/book/src/editor.md
+++ b/book/src/editor.md
@@ -138,13 +138,8 @@
 | `file-type` | The type of the opened file |
 | `diagnostics` | The number of warnings and/or errors |
 | `workspace-diagnostics` | The number of warnings and/or errors on workspace |
-<<<<<<< Conflict 1 of 1
-%%%%%%% Changes from base to side #1
- | `selections` | The number of active selections |
-+| `search-position` | Current search match and total matches in the view `[<current>/<total>]` |
-+++++++ Contents of side #2
 | `selections` | The primary selection index out of the number of active selections |
->>>>>>> Conflict 1 of 1 ends
+| `search-position` | Current search match and total matches in the view `[<current>/<total>]` |
 | `primary-selection-length` | The number of characters currently in primary selection |
 | `position` | The cursor position |
 | `position-percentage` | The cursor position as a percentage of the total number of lines |
diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs
index 0756033ab3..100a9fa3b1 100644
--- a/helix-term/src/ui/statusline.rs
+++ b/helix-term/src/ui/statusline.rs
@@ -556,15 +556,15 @@
     }
 }
 
-fn render_search_position<F>(context: &mut RenderContext, write: F)
+fn render_search_position<'a, F>(context: &mut RenderContext<'a>, write: F)
 where
-    F: Fn(&mut RenderContext, String, Option<Style>) + Copy,
+    F: Fn(&mut RenderContext<'a>, Span<'a>) + Copy,
 {
     if let Some(SearchMatch { idx, count }) = context.doc.get_last_search_match(context.view.id) {
         let count_str = match count {
             SearchMatchLimit::Limitless(count) => format!("{}", count),
             SearchMatchLimit::Limited(max) => format!(">{}", max),
         };
-        write(context, format!(" [{}/{}] ", idx, count_str), None);
+        write(context, format!(" [{}/{}] ", idx, count_str).into());
     }
 }

I just rebased my branch.

@Septias

This comment was marked as spam.

@Axlefublr
Copy link
Contributor

Axlefublr commented Dec 10, 2025

discovered an interesting bug. set editor.search.wrap-around to false (disabling it), then go beyond / after the last search match and press N to get back to it. N no longer works.
it seems like the implementation relies on wrapping, as with wrap-around enabled the N works but tells me “Wrapped around document”, while by all accounts it shouldn't have needed to.

Here's a recording:

compressed.mp4

After I go past the last search match, I spam press N to go back to it, but I get a “No search matches” error message instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-command Area: Commands A-gui Area: Helix gui improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants