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:
6 files changed
+91
-6
No files matched your search
+19
-1
@@ -2,7 +2,7 @@
|
||||
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import re
|
||||
from collections.abc import Callable, Generator, Iterable, Sequence
|
||||
from collections.abc import Callable, Generator, Iterable, Mapping, Sequence
|
||||
from re import Pattern
|
||||
from typing import Union
|
||||
|
||||
@@ -29,6 +29,24 @@ def marker_from_regex(expression: Union[str, 'Pattern[str]'], color: int, flags:
|
||||
return marker
|
||||
|
||||
|
||||
def marker_from_spans(spans: Mapping[str, Sequence[tuple[int, int, int]]]) -> MarkerFunc:
|
||||
"""A marker built from pre-computed spans, keyed by the text of their line.
|
||||
|
||||
Each span is (start, end, color), where color is a mark number. Marker
|
||||
functions receive one line at a time without its number, hence the lookup
|
||||
by text.
|
||||
"""
|
||||
|
||||
def marker(text: str, left_address: int, right_address: int, color_address: int) -> Generator[None, None, None]:
|
||||
for start, end, color in spans.get(text, ()):
|
||||
set_uint_at_address(left_address, start)
|
||||
set_uint_at_address(right_address, end - 1)
|
||||
set_uint_at_address(color_address, max(1, min(color, 3)))
|
||||
yield
|
||||
|
||||
return marker
|
||||
|
||||
|
||||
def marker_from_multiple_regex(regexes: Iterable[tuple[int, str]], flags: int = re.UNICODE) -> MarkerFunc:
|
||||
expr = ''
|
||||
color_map = {}
|
||||
|
||||
Reference in new issue
Block a user