mirror of
https://github.com/walles/moar.git
synced 2024-09-11 12:15:43 +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:
|
case twin.EventTerminalBackgroundDetected:
|
||||||
// Do nothing, we don't care about background color updates
|
// 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:
|
default:
|
||||||
log.Warnf("Unhandled event type: %v", event)
|
log.Warnf("Unhandled event type: %v", event)
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,10 @@ const (
|
|||||||
searchCommandDone
|
searchCommandDone
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type eventGoToLine struct {
|
||||||
|
lineNumber linenumbers.LineNumber
|
||||||
|
}
|
||||||
|
|
||||||
type PagerModeSearch struct {
|
type PagerModeSearch struct {
|
||||||
pager *Pager
|
pager *Pager
|
||||||
|
|
||||||
@ -83,7 +87,7 @@ func (m *PagerModeSearch) initSearcher() {
|
|||||||
case searchCommandSearch:
|
case searchCommandSearch:
|
||||||
found := m.searcherSearch()
|
found := m.searcherSearch()
|
||||||
if found != nil {
|
if found != nil {
|
||||||
FIXME: Tell the pager to scroll to this position
|
m.pager.screen.Events() <- eventGoToLine{*found}
|
||||||
}
|
}
|
||||||
case searchCommandDone:
|
case searchCommandDone:
|
||||||
return
|
return
|
||||||
|
24
m/search.go
24
m/search.go
@ -6,30 +6,6 @@ import (
|
|||||||
"github.com/walles/moar/m/linenumbers"
|
"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
|
// 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
|
// the screen lines. That's why we're using a line number rather than a
|
||||||
// scrollPosition for searching.
|
// scrollPosition for searching.
|
||||||
|
Loading…
Reference in New Issue
Block a user