Skip to content

Commit cf5695f

Browse files
committed
Allow clicking in main view to focus it
1 parent 6a3f583 commit cf5695f

File tree

4 files changed

+38
-42
lines changed

4 files changed

+38
-42
lines changed

pkg/gui/controllers/commits_files_controller.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,6 @@ func (self *CommitFilesController) GetKeybindings(opts types.KeybindingsOpts) []
135135
return bindings
136136
}
137137

138-
func (self *CommitFilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
139-
return []*gocui.ViewMouseBinding{
140-
{
141-
ViewName: "main",
142-
Key: gocui.MouseLeft,
143-
Handler: self.onClickMain,
144-
FocusedView: self.context().GetViewName(),
145-
},
146-
}
147-
}
148-
149138
func (self *CommitFilesController) context() *context.CommitFilesContext {
150139
return self.c.Contexts().CommitFiles
151140
}
@@ -175,14 +164,6 @@ func (self *CommitFilesController) GetOnRenderToMain() func() {
175164
}
176165
}
177166

178-
func (self *CommitFilesController) onClickMain(opts gocui.ViewMouseBindingOpts) error {
179-
node := self.context().GetSelected()
180-
if node == nil {
181-
return nil
182-
}
183-
return self.enterCommitFile(node, types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: opts.Y})
184-
}
185-
186167
func (self *CommitFilesController) copyDiffToClipboard(path string, toastMessage string) error {
187168
from, to := self.context().GetFromAndToForDiff()
188169
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(from)

pkg/gui/controllers/files_controller.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,24 +208,12 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types
208208

209209
func (self *FilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
210210
return []*gocui.ViewMouseBinding{
211-
{
212-
ViewName: "main",
213-
Key: gocui.MouseLeft,
214-
Handler: self.onClickMain,
215-
FocusedView: self.context().GetViewName(),
216-
},
217211
{
218212
ViewName: "mergeConflicts",
219213
Key: gocui.MouseLeft,
220214
Handler: self.onClickMain,
221215
FocusedView: self.context().GetViewName(),
222216
},
223-
{
224-
ViewName: "secondary",
225-
Key: gocui.MouseLeft,
226-
Handler: self.onClickSecondary,
227-
FocusedView: self.context().GetViewName(),
228-
},
229217
}
230218
}
231219

@@ -1188,10 +1176,6 @@ func (self *FilesController) onClickMain(opts gocui.ViewMouseBindingOpts) error
11881176
return self.EnterFile(types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: opts.Y})
11891177
}
11901178

1191-
func (self *FilesController) onClickSecondary(opts gocui.ViewMouseBindingOpts) error {
1192-
return self.EnterFile(types.OnFocusOpts{ClickedWindowName: "secondary", ClickedViewLineIdx: opts.Y})
1193-
}
1194-
11951179
func (self *FilesController) fetch() error {
11961180
return self.c.WithWaitingStatus(self.c.Tr.FetchingStatus, func(task gocui.Task) error {
11971181
if err := self.fetchAux(task); err != nil {

pkg/gui/controllers/switch_to_focused_main_view_controller.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package controllers
22

33
import (
4+
"github.com/jesseduffield/gocui"
45
"github.com/jesseduffield/lazygit/pkg/gui/types"
56
)
67

@@ -37,12 +38,41 @@ func (self *SwitchToFocusedMainViewController) GetKeybindings(opts types.Keybind
3738
return bindings
3839
}
3940

41+
func (self *SwitchToFocusedMainViewController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
42+
return []*gocui.ViewMouseBinding{
43+
{
44+
ViewName: "main",
45+
Key: gocui.MouseLeft,
46+
Handler: self.onClickMain,
47+
FocusedView: self.context.GetViewName(),
48+
},
49+
{
50+
ViewName: "secondary",
51+
Key: gocui.MouseLeft,
52+
Handler: self.onClickSecondary,
53+
FocusedView: self.context.GetViewName(),
54+
},
55+
}
56+
}
57+
4058
func (self *SwitchToFocusedMainViewController) Context() types.Context {
4159
return self.context
4260
}
4361

62+
func (self *SwitchToFocusedMainViewController) onClickMain(opts gocui.ViewMouseBindingOpts) error {
63+
return self.focusMainView("main")
64+
}
65+
66+
func (self *SwitchToFocusedMainViewController) onClickSecondary(opts gocui.ViewMouseBindingOpts) error {
67+
return self.focusMainView("secondary")
68+
}
69+
4470
func (self *SwitchToFocusedMainViewController) handleFocusMainView() error {
45-
mainViewContext := self.c.Helpers().Window.GetContextForWindow("main")
71+
return self.focusMainView("main")
72+
}
73+
74+
func (self *SwitchToFocusedMainViewController) focusMainView(mainViewName string) error {
75+
mainViewContext := self.c.Helpers().Window.GetContextForWindow(mainViewName)
4676
mainViewContext.SetParentContext(self.context)
4777
if context := mainViewContext.(types.ISearchableContext); context != nil {
4878
context.ClearSearchString()

pkg/integration/tests/ui/range_select.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
3939
// separately)
4040
// In both views we're going to have 10 lines starting from 'line 1' going down to
4141
// 'line 10'.
42-
fileContent := ""
42+
fileContent := "staged\n"
4343
total := 10
4444
for i := 1; i <= total; i++ {
4545
remaining := total - i + 1
4646
// Commits are displayed in reverse order so to we need to create them in reverse to have them appear as 'line 1', 'line 2' etc.
4747
shell.EmptyCommit(fmt.Sprintf("line %d", remaining))
4848
fileContent = fmt.Sprintf("%sline %d\n", fileContent, i)
4949
}
50-
shell.CreateFile("file1", fileContent)
50+
shell.CreateFileAndAdd("file1", "staged\n")
51+
shell.UpdateFile("file1", fileContent)
5152
},
5253
Run: func(t *TestDriver, keys config.KeybindingConfig) {
53-
assertRangeSelectBehaviour := func(v *ViewDriver, otherView *ViewDriver, lineIdxOfFirstItem int) {
54+
assertRangeSelectBehaviour := func(v *ViewDriver, focusOtherView func(), lineIdxOfFirstItem int) {
5455
v.
5556
SelectedLines(
5657
Contains("line 1"),
@@ -154,7 +155,7 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
154155
)
155156

156157
// Click in view, press shift+arrow -> nonsticky range
157-
otherView.Focus()
158+
focusOtherView()
158159
v.Click(1, lineIdxOfFirstItem).
159160
SelectedLines(
160161
Contains("line 1"),
@@ -166,7 +167,7 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
166167
)
167168
}
168169

169-
assertRangeSelectBehaviour(t.Views().Commits().Focus(), t.Views().Branches(), 0)
170+
assertRangeSelectBehaviour(t.Views().Commits().Focus(), func() { t.Views().Branches().Focus() }, 0)
170171

171172
t.Views().Files().
172173
Focus().
@@ -175,6 +176,6 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
175176
).
176177
PressEnter()
177178

178-
assertRangeSelectBehaviour(t.Views().Staging().IsFocused(), t.Views().Files(), 6)
179+
assertRangeSelectBehaviour(t.Views().Staging().IsFocused(), func() { t.Views().Staging().PressTab() }, 6)
179180
},
180181
})

0 commit comments

Comments
 (0)