mirror of
https://github.com/walles/moar.git
synced 2024-08-16 15:30:34 +03:00
Compare commits
2 Commits
89955fa0e6
...
b835e9a23d
Author | SHA1 | Date | |
---|---|---|---|
|
b835e9a23d | ||
|
f0e11a4e0e |
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
24
m/search.go
24
m/search.go
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user