1
1
mirror of https://github.com/walles/moar.git synced 2024-08-16 15:30:34 +03:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Johan Walles
b835e9a23d Fix the warnings 2024-05-15 20:34:01 +02:00
Johan Walles
f0e11a4e0e WIP: Go to the line with the search hit
Some warnings, we should at least be using scrollPosition.isVisible().
2024-05-15 20:28:14 +02:00
3 changed files with 11 additions and 25 deletions

View File

@ -445,6 +445,12 @@ func (p *Pager) StartPaging(screen twin.Screen, chromaStyle *chroma.Style, chrom
case twin.EventTerminalBackgroundDetected:
// Do nothing, we don't care about background color updates
case eventGoToLine:
line := NewScrollPositionFromLineNumber(event.lineNumber, "goToLine")
if !line.isVisible(p) {
p.scrollPosition = line
}
default:
log.Warnf("Unhandled event type: %v", event)
}

View File

@ -18,6 +18,10 @@ const (
searchCommandDone
)
type eventGoToLine struct {
lineNumber linenumbers.LineNumber
}
type PagerModeSearch struct {
pager *Pager
@ -83,7 +87,7 @@ func (m *PagerModeSearch) initSearcher() {
case searchCommandSearch:
found := m.searcherSearch()
if found != nil {
FIXME: Tell the pager to scroll to this position
m.pager.screen.Events() <- eventGoToLine{*found}
}
case searchCommandDone:
return

View File

@ -6,30 +6,6 @@ import (
"github.com/walles/moar/m/linenumbers"
)
func (p *Pager) scrollToSearchHits() {
if p.searchPattern == nil {
// This is not a search
return
}
firstHitPosition := p.findFirstHit(*p.scrollPosition.lineNumber(p), nil, false)
if firstHitPosition == nil {
// Try again from the top
firstHitPosition = p.findFirstHit(linenumbers.LineNumber{}, p.scrollPosition.lineNumber(p), false)
}
if firstHitPosition == nil {
// No match, give up
return
}
if firstHitPosition.isVisible(p) {
// Already on-screen, never mind
return
}
p.scrollPosition = *firstHitPosition
}
// NOTE: When we search, we do that by looping over the *input lines*, not
// the screen lines. That's why we're using a line number rather than a
// scrollPosition for searching.