1
1
mirror of https://github.com/walles/moar.git synced 2024-11-05 04:24:19 +03:00

Fix search highlighting

After scrolling right.
This commit is contained in:
Johan Walles 2019-08-03 23:21:40 +02:00
parent df9920c11c
commit 5bb74e4f10
2 changed files with 12 additions and 5 deletions

View File

@ -89,9 +89,6 @@ FIXME: Go release instructions
TODO 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 * Change out-of-file visualization to writing --- after the end of the
file and leaving the rest of the screen blank. file and leaving the rest of the screen blank.
@ -141,3 +138,6 @@ Done
line-continuation markers at the rightmost column. This really line-continuation markers at the rightmost column. This really
means our truncation code must work even with things like tabs and means our truncation code must work even with things like tabs and
various control characters. various control characters.
* Make sure search hits are highlighted even when we have to scroll right
to see them

View File

@ -97,10 +97,17 @@ func NewPager(r *Reader) *_Pager {
func (p *_Pager) _AddLine(logger *log.Logger, lineNumber int, line string) { func (p *_Pager) _AddLine(logger *log.Logger, lineNumber int, line string) {
pos := 0 pos := 0
stringIndexAtColumnZero := p.leftColumnZeroBased
if p.leftColumnZeroBased > 0 { if p.leftColumnZeroBased > 0 {
// Indicate that it's possible to scroll left // Indicate that it's possible to scroll left
p.screen.SetContent(pos, lineNumber, '<', nil, tcell.StyleDefault.Reverse(true)) p.screen.SetContent(pos, lineNumber, '<', nil, tcell.StyleDefault.Reverse(true))
pos++ 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) tokens, plainString := TokensFromString(logger, line)
@ -119,8 +126,8 @@ func (p *_Pager) _AddLine(logger *log.Logger, lineNumber int, line string) {
} }
style := token.Style style := token.Style
if matchRanges.InRange(pos) { if matchRanges.InRange(pos + stringIndexAtColumnZero) {
// FIXME: This doesn't work if the style is already reversed // Search hits in reverse video
style = style.Reverse(true) style = style.Reverse(true)
} }