From 5bb74e4f1017179ad24a84e3a5df43bcc24652c3 Mon Sep 17 00:00:00 2001 From: Johan Walles Date: Sat, 3 Aug 2019 23:21:40 +0200 Subject: [PATCH] Fix search highlighting After scrolling right. --- README.md | 6 +++--- m/pager.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 55f4628..b7b91b0 100644 --- a/README.md +++ b/README.md @@ -89,9 +89,6 @@ FIXME: Go release instructions TODO ---- -* Make sure search hits are highlighted even when we have to scroll right - to see them - * Change out-of-file visualization to writing --- after the end of the file and leaving the rest of the screen blank. @@ -141,3 +138,6 @@ Done line-continuation markers at the rightmost column. This really means our truncation code must work even with things like tabs and various control characters. + +* Make sure search hits are highlighted even when we have to scroll right + to see them diff --git a/m/pager.go b/m/pager.go index 94fa4d1..47d21eb 100644 --- a/m/pager.go +++ b/m/pager.go @@ -97,10 +97,17 @@ func NewPager(r *Reader) *_Pager { func (p *_Pager) _AddLine(logger *log.Logger, lineNumber int, line string) { pos := 0 + stringIndexAtColumnZero := p.leftColumnZeroBased if p.leftColumnZeroBased > 0 { // Indicate that it's possible to scroll left p.screen.SetContent(pos, lineNumber, '<', nil, tcell.StyleDefault.Reverse(true)) pos++ + + // This code can be verified by searching for "monkeys" in + // sample-files/long-and-wide.txt and scrolling right. If the + // "monkeys" highlight is in the right place both before and + // after scrolling right then this code is good. + stringIndexAtColumnZero-- } tokens, plainString := TokensFromString(logger, line) @@ -119,8 +126,8 @@ func (p *_Pager) _AddLine(logger *log.Logger, lineNumber int, line string) { } style := token.Style - if matchRanges.InRange(pos) { - // FIXME: This doesn't work if the style is already reversed + if matchRanges.InRange(pos + stringIndexAtColumnZero) { + // Search hits in reverse video style = style.Reverse(true) }