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
----
* 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

View File

@ -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)
}