mirror of
https://github.com/walles/moar.git
synced 2024-09-11 12:15:43 +03:00
Move gotoLineString to where it should be
It only lives as long as the GotoLine mode does, so it should be part of that struct.
This commit is contained in:
parent
98b83c45d6
commit
a9d1ad542d
@ -53,9 +53,8 @@ type Pager struct {
|
||||
// mode is better?
|
||||
mode PagerMode
|
||||
|
||||
searchString string
|
||||
searchPattern *regexp.Regexp
|
||||
gotoLineString string
|
||||
searchString string
|
||||
searchPattern *regexp.Regexp
|
||||
|
||||
// We used to have a "Following" field here. If you want to follow, set
|
||||
// TargetLineNumber to LineNumberMax() instead, see below.
|
||||
|
@ -10,15 +10,17 @@ import (
|
||||
|
||||
type PagerModeGotoLine struct {
|
||||
pager *Pager
|
||||
|
||||
gotoLineString string
|
||||
}
|
||||
|
||||
func (m PagerModeGotoLine) drawFooter(_ string, _ string) {
|
||||
func (m *PagerModeGotoLine) drawFooter(_ string, _ string) {
|
||||
p := m.pager
|
||||
|
||||
_, height := p.screen.Size()
|
||||
|
||||
pos := 0
|
||||
for _, token := range "Go to line number: " + p.gotoLineString {
|
||||
for _, token := range "Go to line number: " + m.gotoLineString {
|
||||
p.screen.SetCell(pos, height-1, twin.NewCell(token, twin.StyleDefault))
|
||||
pos++
|
||||
}
|
||||
@ -27,12 +29,12 @@ func (m PagerModeGotoLine) drawFooter(_ string, _ string) {
|
||||
p.screen.SetCell(pos, height-1, twin.NewCell(' ', twin.StyleDefault.WithAttr(twin.AttrReverse)))
|
||||
}
|
||||
|
||||
func (m PagerModeGotoLine) onKey(key twin.KeyCode) {
|
||||
func (m *PagerModeGotoLine) onKey(key twin.KeyCode) {
|
||||
p := m.pager
|
||||
|
||||
switch key {
|
||||
case twin.KeyEnter:
|
||||
newLineNumber, err := strconv.Atoi(p.gotoLineString)
|
||||
newLineNumber, err := strconv.Atoi(m.gotoLineString)
|
||||
if err == nil {
|
||||
p.scrollPosition = NewScrollPositionFromLineNumber(
|
||||
linenumbers.LineNumberFromOneBased(newLineNumber),
|
||||
@ -45,11 +47,11 @@ func (m PagerModeGotoLine) onKey(key twin.KeyCode) {
|
||||
p.mode = PagerModeViewing{pager: p}
|
||||
|
||||
case twin.KeyBackspace, twin.KeyDelete:
|
||||
if len(p.gotoLineString) == 0 {
|
||||
if len(m.gotoLineString) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
p.gotoLineString = removeLastChar(p.gotoLineString)
|
||||
m.gotoLineString = removeLastChar(m.gotoLineString)
|
||||
|
||||
default:
|
||||
log.Tracef("Unhandled goto key event %v, treating as a viewing key event", key)
|
||||
@ -58,7 +60,7 @@ func (m PagerModeGotoLine) onKey(key twin.KeyCode) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m PagerModeGotoLine) onRune(char rune) {
|
||||
func (m *PagerModeGotoLine) onRune(char rune) {
|
||||
p := m.pager
|
||||
|
||||
if char == 'q' {
|
||||
@ -73,12 +75,12 @@ func (m PagerModeGotoLine) onRune(char rune) {
|
||||
return
|
||||
}
|
||||
|
||||
newGotoLineString := p.gotoLineString + string(char)
|
||||
newGotoLineString := m.gotoLineString + string(char)
|
||||
_, err := strconv.Atoi(newGotoLineString)
|
||||
if err != nil {
|
||||
log.Debugf("Got non-number goto rune '%s'/0x%08x: %s", string(char), int32(char), err)
|
||||
return
|
||||
}
|
||||
|
||||
p.gotoLineString = newGotoLineString
|
||||
m.gotoLineString = newGotoLineString
|
||||
}
|
||||
|
@ -150,9 +150,8 @@ func (m PagerModeViewing) onRune(char rune) {
|
||||
p.searchPattern = nil
|
||||
|
||||
case 'g':
|
||||
p.mode = PagerModeGotoLine{pager: p}
|
||||
p.mode = &PagerModeGotoLine{pager: p}
|
||||
p.TargetLineNumber = nil
|
||||
p.gotoLineString = ""
|
||||
|
||||
// Should match the pagermode-not-found.go previous-search-hit bindings
|
||||
case 'n':
|
||||
|
@ -15,7 +15,7 @@ func modeName(pager *Pager) string {
|
||||
return "NotFound"
|
||||
case PagerModeSearch:
|
||||
return "Search"
|
||||
case PagerModeGotoLine:
|
||||
case *PagerModeGotoLine:
|
||||
return "GotoLine"
|
||||
default:
|
||||
panic("Unknown pager mode")
|
||||
|
Loading…
Reference in New Issue
Block a user