1
1
package controllers
2
2
3
3
import (
4
+ "github.com/jesseduffield/lazygit/pkg/gui/context"
4
5
"github.com/jesseduffield/lazygit/pkg/gui/types"
6
+ "github.com/jesseduffield/lazygit/pkg/tasks"
5
7
)
6
8
7
9
type MainViewController struct {
8
10
baseController
9
- c * ControllerCommon
11
+ c * ControllerCommon
12
+ viewBufferManagerMap * map [string ]* tasks.ViewBufferManager
10
13
11
- context types. Context
12
- otherContext types. Context
14
+ context * context. MainContext
15
+ otherContext * context. MainContext
13
16
}
14
17
15
18
var _ types.IController = & MainViewController {}
16
19
17
20
func NewMainViewController (
18
21
c * ControllerCommon ,
19
- context types.Context ,
20
- otherContext types.Context ,
22
+ context * context.MainContext ,
23
+ otherContext * context.MainContext ,
24
+ viewBufferManagerMap * map [string ]* tasks.ViewBufferManager ,
21
25
) * MainViewController {
22
26
return & MainViewController {
23
- baseController : baseController {},
24
- c : c ,
25
- context : context ,
26
- otherContext : otherContext ,
27
+ baseController : baseController {},
28
+ c : c ,
29
+ viewBufferManagerMap : viewBufferManagerMap ,
30
+ context : context ,
31
+ otherContext : otherContext ,
27
32
}
28
33
}
29
34
@@ -41,6 +46,13 @@ func (self *MainViewController) GetKeybindings(opts types.KeybindingsOpts) []*ty
41
46
Handler : self .escape ,
42
47
Description : self .c .Tr .ExitFocusedMainView ,
43
48
},
49
+ {
50
+ // overriding this because we want to read all of the task's output before we start searching
51
+ Key : opts .GetKey (opts .Config .Universal .StartSearch ),
52
+ Handler : self .openSearch ,
53
+ Description : self .c .Tr .StartSearch ,
54
+ Tag : "navigation" ,
55
+ },
44
56
}
45
57
}
46
58
@@ -61,3 +73,15 @@ func (self *MainViewController) escape() error {
61
73
self .c .Context ().Pop ()
62
74
return nil
63
75
}
76
+
77
+ func (self * MainViewController ) openSearch () error {
78
+ if manager , ok := (* self .viewBufferManagerMap )[self .context .GetViewName ()]; ok {
79
+ manager .ReadToEnd (func () {
80
+ self .c .OnUIThread (func () error {
81
+ return self .c .Helpers ().Search .OpenSearchPrompt (self .context )
82
+ })
83
+ })
84
+ }
85
+
86
+ return nil
87
+ }
0 commit comments