refactor: Separate search match attributes for prefix and content
This commit is contained in:
parent
b50a2def03
commit
787fbc39d1
18
gtm
18
gtm
|
|
@ -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,12 +602,16 @@ 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
|
||||
display_content = content
|
||||
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:
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue