|
42 | 42 |
|
43 | 43 | // Selection Style |
44 | 44 | selectedStyle = lipgloss.NewStyle().Background(lipgloss.Color("#555555")).Foreground(lipgloss.Color("#ffffff")) |
| 45 | + |
| 46 | + // Match Style (Search Matches) |
| 47 | + matchStyle = lipgloss.NewStyle().Background(lipgloss.Color("#FFFF00")).Foreground(lipgloss.Color("#000000")) |
45 | 48 | ) |
46 | 49 |
|
47 | 50 | type Point struct { |
@@ -724,6 +727,8 @@ func (m Model) View() string { |
724 | 727 | // 2. Wrap vs Horizontal Scroll |
725 | 728 | if m.wrap { |
726 | 729 | // WRAP MODE |
| 730 | + // 0. Highlight Matches (Priority) |
| 731 | + line = highlightMatches(line, m.filterText, m.regexMode) |
727 | 732 | line = highlightLine(line) |
728 | 733 | if isBookmarked { |
729 | 734 | line = "🔖 " + line |
@@ -851,6 +856,7 @@ func (m Model) View() string { |
851 | 856 | visiblePart := string(rawRunes[m.xOffset : end]) |
852 | 857 |
|
853 | 858 | // Highlight visible part |
| 859 | + visiblePart = highlightMatches(visiblePart, m.filterText, m.regexMode) |
854 | 860 | line = highlightLine(visiblePart) |
855 | 861 |
|
856 | 862 | // 2. Selection Highlighting (Lazy) |
@@ -1028,6 +1034,30 @@ func highlightLine(line string) string { |
1028 | 1034 | return line |
1029 | 1035 | } |
1030 | 1036 |
|
| 1037 | +func highlightMatches(line, pattern string, isRegex bool) string { |
| 1038 | + if pattern == "" { |
| 1039 | + return line |
| 1040 | + } |
| 1041 | + |
| 1042 | + var re *regexp.Regexp |
| 1043 | + var err error |
| 1044 | + |
| 1045 | + if isRegex { |
| 1046 | + re, err = regexp.Compile(pattern) |
| 1047 | + } else { |
| 1048 | + // Case insensitive literal match |
| 1049 | + re, err = regexp.Compile("(?i)" + regexp.QuoteMeta(pattern)) |
| 1050 | + } |
| 1051 | + |
| 1052 | + if err != nil { |
| 1053 | + return line // Return regex errors as is (or handle better?) |
| 1054 | + } |
| 1055 | + |
| 1056 | + return re.ReplaceAllStringFunc(line, func(match string) string { |
| 1057 | + return matchStyle.Render(match) |
| 1058 | + }) |
| 1059 | +} |
| 1060 | + |
1031 | 1061 |
|
1032 | 1062 |
|
1033 | 1063 | func stripAnsi(str string) string { |
|
0 commit comments