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)
|
||||
query = state.search_query.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
|
||||
while pos < len(content_lower):
|
||||
match_pos = content_lower.find(query, pos)
|
||||
|
|
@ -625,21 +630,12 @@ def draw_right_pane(stdscr, state):
|
|||
break
|
||||
|
||||
if match_pos + len(query) <= len(display_content):
|
||||
# Draw text before match
|
||||
if match_pos > 0:
|
||||
stdscr.addnstr(display_row, content_start, display_content[:match_pos], match_pos)
|
||||
|
||||
# Draw the match with highlighting
|
||||
# Draw just the match with highlighting
|
||||
match_text = display_content[match_pos:match_pos + len(query)]
|
||||
stdscr.addnstr(display_row, content_start + match_pos, match_text, len(query), content_attr)
|
||||
|
||||
# Draw text after match
|
||||
if match_pos + len(query) < len(display_content):
|
||||
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
|
||||
# Move to position after this match to find the next one
|
||||
pos = match_pos + len(query)
|
||||
|
||||
display_row += 1
|
||||
else:
|
||||
|
|
|
|||
Loading…
Reference in New Issue