fix(search): allow searching for a literal \c or \r
A query that starts with one of the two modifier prefixes could not be escaped, so the text itself was unreachable: \c and \r were always consumed as modifiers and the query ended up empty. A doubled backslash now ends the modifier section and stands for the literal backslash, and the help line and the docs document it. Fixes #48
This commit is contained in:
5 files changed
+37
-6
No files matched your search
@@ -6,7 +6,8 @@
|
||||
The query parser and the matcher live here, away from the screen code, so that
|
||||
they can be tested without a running terminal. A query can start with two
|
||||
modifiers, in any order: ``\\c`` makes matching case sensitive and ``\\r``
|
||||
treats the query as a regular expression.
|
||||
treats the query as a regular expression. A doubled backslash escapes the
|
||||
modifier syntax, so that the two prefixes can be searched for literally.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -57,6 +58,11 @@ def parse_query(raw: str) -> Query:
|
||||
case_sensitive = is_regex = False
|
||||
while len(text) > 1 and text[0] == '\\':
|
||||
modifier = text[1].lower()
|
||||
if modifier == '\\':
|
||||
# A doubled backslash stands for a literal one and ends the modifier
|
||||
# section, which is the only way to search for \c or \r themselves.
|
||||
text = text[1:]
|
||||
break
|
||||
if modifier == CASE_SENSITIVE_MODIFIER:
|
||||
case_sensitive = True
|
||||
elif modifier == REGEX_MODIFIER:
|
||||
|
||||
+6
-2
@@ -2676,7 +2676,8 @@ class Window:
|
||||
'sc',
|
||||
"""
|
||||
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. Matches are navigated with n and N and
|
||||
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.
|
||||
""",
|
||||
)
|
||||
@@ -2691,7 +2692,10 @@ class Window:
|
||||
self.clear_scrollback_search()
|
||||
|
||||
get_boss().get_line(
|
||||
_('Search the scrollback. Prefix the query with \\c for a case sensitive search and \\r for a regular expression.'),
|
||||
_(
|
||||
'Search the scrollback. Prefix the query with \\c for a case sensitive search and \\r for a regular expression.'
|
||||
' Write a double backslash to search for those strings literally.'
|
||||
),
|
||||
done,
|
||||
window=self,
|
||||
prompt=_('search> '),
|
||||
|
||||
Reference in new issue
Block a user