M browser.go => browser.go +15 -0
@@ 67,6 67,8 @@ type Browser struct {
hints []Hint
hintlen int
+ lastCmd string
+
message struct {
text string
err bool
@@ 262,6 264,7 @@ func (b *Browser) Event(event tcell.Event) {
case *ui.EventTextInput:
b.mode = ModeNormal
if event.NoInput() {
+ b.CleanupLastCommand()
return
}
b.RunCommand(strings.Fields(event.Text())...)
@@ 608,6 611,7 @@ func (b *Browser) RunCommand(args ...string) {
b.Error(fmt.Errorf("%q is not a command", args[0]))
return
}
+ b.lastCmd = args[0]
if err := c.Func(b, args[1:]...); err != nil {
b.Error(err)
}
@@ 622,11 626,22 @@ func (b *Browser) PreviewCommand(args ...string) {
if !ok || !c.Preview {
return
}
+ b.lastCmd = args[0]
if err := c.Func(b, args[1:]...); err != nil {
b.Error(err)
}
}
+func (b *Browser) CleanupLastCommand() {
+ b.clearMessage()
+ c, ok := commands[b.lastCmd]
+ b.lastCmd = ""
+ if !ok || c.Cleanup == nil {
+ return
+ }
+ c.Cleanup(b)
+}
+
// Previous switches to the previous tab.
func (b *Browser) Previous() {
if b.tab > 0 {
M command.go => command.go +11 -0
@@ 13,6 13,7 @@ import (
type Command struct {
Func func(b *Browser, args ...string) error
+ Cleanup func(b *Browser)
Preview bool
}
@@ 22,6 23,7 @@ var commands = map[string]Command{
},
"find": Command{
Func: cmdFind,
+ Cleanup: cleanupFind,
Preview: true,
},
"follow": Command{
@@ 112,6 114,15 @@ func cmdFind(b *Browser, args ...string) error {
return nil
}
+func cleanupFind(b *Browser) {
+ tab := b.tabs[b.tab]
+ text := tab.Text()
+ if text == nil {
+ return
+ }
+ text.Find("")
+}
+
func cmdFollow(b *Browser, args ...string) error {
return b.FollowMode()
}