feat(search): highlight the current match in its own color

Every match of the in-place search used the same mark color, so after pressing
n or N the only hint of the current match was the counter in the window title,
which is easy to miss on a short query or a dense screen. The marker now colors
the current match with the second mark color and keeps the rest on the first
one, rebuilding the marker whenever the index changes.

Fixes #51
This commit is contained in:
BlackAngelTV committed 2026-12-03 10:06:04 +01:00
1 parent b406be9394
commit 4df542f590
6 files changed
+91 -6

No files matched your search

+17 -4
View File
@@ -827,6 +827,7 @@ class Window:
self.actions_on_removal: list[Callable[['Window'], None]] = []
self.current_marker_spec: tuple[str, str | tuple[tuple[int, str], ...]] | None = None
self.scrollback_search: ScrollbackSearch | None = None
self.scrollback_search_spans: dict[str, tuple[tuple[int, int, int], ...]] = {}
self.scrollback_search_mode: str = ''
self.scrollback_search_saved_marker: tuple[str, str | tuple[tuple[int, str], ...]] | None = None
self.scrollback_search_saved_title: str | None = None
@@ -2678,7 +2679,8 @@ class Window:
Search the scrollback in place, highlighting every match. Prefix the query with \\c for a case
sensitive search and with \\r for a regular expression. To search for those two strings literally,
write a double backslash instead (``\\\\c`` and ``\\\\r``). Matches are navigated with n and N and
the search ends with Escape. The [current/total] counter is shown in the window title.
the search ends with Escape. The [current/total] counter is shown in the window title and the
current match uses the second mark color.
""",
)
def search_scrollback_prompt(self) -> bool | None:
@@ -2728,12 +2730,12 @@ class Window:
ring_bell(self.os_window_id)
return
self.clear_scrollback_search()
from .marks import marker_from_regex
self.scrollback_search = ScrollbackSearch(query, pattern, matches, total_lines=len(lines))
search = ScrollbackSearch(query, pattern, matches, total_lines=len(lines))
self.scrollback_search = search
self.scrollback_search_spans = search.marker_spans(lines)
self.scrollback_search_saved_marker = self.current_marker_spec
self.scrollback_search_saved_title = self.override_title
self.screen.set_marker(marker_from_regex(pattern, 1))
self._push_scrollback_search_mode()
self._goto_scrollback_match(0)
@@ -2742,6 +2744,7 @@ class Window:
if self.scrollback_search is None:
return
self.scrollback_search = None
self.scrollback_search_spans = {}
self.screen.set_marker()
self.current_marker_spec = None
saved = self.scrollback_search_saved_marker
@@ -2785,8 +2788,18 @@ class Window:
search.index = index % len(search.matches)
match = search.matches[search.index]
self.set_title(f'[{search.index + 1}/{len(search.matches)}] {search.query.text}')
self._refresh_scrollback_search_marker()
self.screen.scroll_to_absolute(scroll_offset_for(match, search.total_lines, self.screen.lines))
def _refresh_scrollback_search_marker(self) -> None:
from .marks import marker_from_spans
# Clear first, as set_marker() only releases the previous callable when
# it is called without one. Marking every line again is needed anyway to
# recolor the match that was current until now.
self.screen.set_marker()
self.screen.set_marker(marker_from_spans(self.scrollback_search_spans))
def _push_scrollback_search_mode(self) -> None:
from .fast_data_types import GLFW_FKEY_ESCAPE, GLFW_MOD_SHIFT
from .options.utils import KeyboardMode, KeyDefinition, SingleKey