Skip to content

Commit a640b1d

Browse files
committed
Allow clicking in main view to focus it
1 parent 8456cbd commit a640b1d

File tree

4 files changed

+38
-42
lines changed

4 files changed

+38
-42
lines changed

pkg/gui/controllers/commits_files_controller.go

-19
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

-16
Original file line numberDiff line numberDiff line change
@@ -207,24 +207,12 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types
207207

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

@@ -1109,10 +1097,6 @@ func (self *FilesController) onClickMain(opts gocui.ViewMouseBindingOpts) error
11091097
return self.EnterFile(types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: opts.Y})
11101098
}
11111099

1112-
func (self *FilesController) onClickSecondary(opts gocui.ViewMouseBindingOpts) error {
1113-
return self.EnterFile(types.OnFocusOpts{ClickedWindowName: "secondary", ClickedViewLineIdx: opts.Y})
1114-
}
1115-
11161100
func (self *FilesController) fetch() error {
11171101
return self.c.WithWaitingStatus(self.c.Tr.FetchingStatus, func(task gocui.Task) error {
11181102
if err := self.fetchAux(task); err != nil {

pkg/gui/controllers/switch_to_focused_main_view_controller.go

+31-1
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

+7-6
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)