feat: Improve search highlighting to underline all matches on the same line
This commit is contained in:
parent
787fbc39d1
commit
f2158e0321
20
gtm
20
gtm
|
|
@ -618,6 +618,11 @@ def draw_right_pane(stdscr, state):
|
||||||
# Find all occurrences of the search query in the content (case-insensitive)
|
# Find all occurrences of the search query in the content (case-insensitive)
|
||||||
query = state.search_query.lower()
|
query = state.search_query.lower()
|
||||||
content_lower = display_content.lower()
|
content_lower = display_content.lower()
|
||||||
|
|
||||||
|
# First, draw the entire line with normal attributes
|
||||||
|
stdscr.addnstr(display_row, content_start, display_content, available_width)
|
||||||
|
|
||||||
|
# Then highlight each match
|
||||||
pos = 0
|
pos = 0
|
||||||
while pos < len(content_lower):
|
while pos < len(content_lower):
|
||||||
match_pos = content_lower.find(query, pos)
|
match_pos = content_lower.find(query, pos)
|
||||||
|
|
@ -625,21 +630,12 @@ def draw_right_pane(stdscr, state):
|
||||||
break
|
break
|
||||||
|
|
||||||
if match_pos + len(query) <= len(display_content):
|
if match_pos + len(query) <= len(display_content):
|
||||||
# Draw text before match
|
# Draw just the match with highlighting
|
||||||
if match_pos > 0:
|
|
||||||
stdscr.addnstr(display_row, content_start, display_content[:match_pos], match_pos)
|
|
||||||
|
|
||||||
# Draw the match with highlighting
|
|
||||||
match_text = display_content[match_pos:match_pos + len(query)]
|
match_text = display_content[match_pos:match_pos + len(query)]
|
||||||
stdscr.addnstr(display_row, content_start + match_pos, match_text, len(query), content_attr)
|
stdscr.addnstr(display_row, content_start + match_pos, match_text, len(query), content_attr)
|
||||||
|
|
||||||
# Draw text after match
|
# Move to position after this match to find the next one
|
||||||
if match_pos + len(query) < len(display_content):
|
pos = match_pos + len(query)
|
||||||
remaining_text = display_content[match_pos + len(query):]
|
|
||||||
stdscr.addnstr(display_row, content_start + match_pos + len(query),
|
|
||||||
remaining_text, len(remaining_text))
|
|
||||||
|
|
||||||
pos = match_pos + 1
|
|
||||||
|
|
||||||
display_row += 1
|
display_row += 1
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue