refactor: Separate search match attributes for prefix and content

This commit is contained in:
n loewen (aider) 2025-06-08 09:55:34 +01:00
parent b50a2def03
commit 787fbc39d1
1 changed files with 11 additions and 7 deletions

18
gtm
View File

@ -585,12 +585,14 @@ def draw_right_pane(stdscr, state):
prefix = " "
attr = curses.A_NORMAL
# If this is a search match, override the attribute
# If this is a search match, override the attribute for the content only
# (we'll apply this when drawing the content, not for the prefix)
search_match_attr = None
if is_search_match:
if is_current_match:
attr = curses.A_REVERSE | curses.A_BOLD
search_match_attr = curses.A_REVERSE | curses.A_BOLD
else:
attr = curses.A_UNDERLINE
search_match_attr = curses.A_UNDERLINE
# Calculate available width for content
content_start = right_start + len(prefix)
@ -600,6 +602,7 @@ def draw_right_pane(stdscr, state):
if len(content) <= available_width or not state.wrap_lines:
# Line fits or wrapping is disabled
if prefix:
# Draw prefix with the original attribute (not search highlighting)
stdscr.addstr(display_row, right_start, prefix, attr)
# If wrapping is disabled, just show what fits in the available width
@ -607,6 +610,9 @@ def draw_right_pane(stdscr, state):
if not state.wrap_lines and len(content) > available_width:
display_content = content[:available_width]
# Use search_match_attr for content if it's a search match
content_attr = search_match_attr if search_match_attr else attr
# If this is a search match, highlight just the matching part
if is_search_match and state.search_query:
# Find all occurrences of the search query in the content (case-insensitive)
@ -618,8 +624,6 @@ def draw_right_pane(stdscr, state):
if match_pos == -1:
break
# Draw the matching part with highlighting
match_attr = attr
if match_pos + len(query) <= len(display_content):
# Draw text before match
if match_pos > 0:
@ -627,7 +631,7 @@ def draw_right_pane(stdscr, state):
# Draw 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), match_attr)
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):
@ -640,7 +644,7 @@ def draw_right_pane(stdscr, state):
display_row += 1
else:
# Normal display without search highlighting
stdscr.addnstr(display_row, content_start, display_content, available_width, attr)
stdscr.addnstr(display_row, content_start, display_content, available_width, content_attr)
display_row += 1
else:
# Line needs wrapping and wrapping is enabled