mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
Allow clicking in main view to focus it
This commit is contained in:
@ -135,17 +135,6 @@ func (self *CommitFilesController) GetKeybindings(opts types.KeybindingsOpts) []
|
|||||||
return bindings
|
return bindings
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CommitFilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
|
|
||||||
return []*gocui.ViewMouseBinding{
|
|
||||||
{
|
|
||||||
ViewName: "main",
|
|
||||||
Key: gocui.MouseLeft,
|
|
||||||
Handler: self.onClickMain,
|
|
||||||
FocusedView: self.context().GetViewName(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *CommitFilesController) context() *context.CommitFilesContext {
|
func (self *CommitFilesController) context() *context.CommitFilesContext {
|
||||||
return self.c.Contexts().CommitFiles
|
return self.c.Contexts().CommitFiles
|
||||||
}
|
}
|
||||||
@ -175,14 +164,6 @@ func (self *CommitFilesController) GetOnRenderToMain() func() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CommitFilesController) onClickMain(opts gocui.ViewMouseBindingOpts) error {
|
|
||||||
node := self.context().GetSelected()
|
|
||||||
if node == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return self.enterCommitFile(node, types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: opts.Y})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *CommitFilesController) copyDiffToClipboard(path string, toastMessage string) error {
|
func (self *CommitFilesController) copyDiffToClipboard(path string, toastMessage string) error {
|
||||||
from, to := self.context().GetFromAndToForDiff()
|
from, to := self.context().GetFromAndToForDiff()
|
||||||
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(from)
|
from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(from)
|
||||||
|
@ -208,24 +208,12 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types
|
|||||||
|
|
||||||
func (self *FilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
|
func (self *FilesController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
|
||||||
return []*gocui.ViewMouseBinding{
|
return []*gocui.ViewMouseBinding{
|
||||||
{
|
|
||||||
ViewName: "main",
|
|
||||||
Key: gocui.MouseLeft,
|
|
||||||
Handler: self.onClickMain,
|
|
||||||
FocusedView: self.context().GetViewName(),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
ViewName: "mergeConflicts",
|
ViewName: "mergeConflicts",
|
||||||
Key: gocui.MouseLeft,
|
Key: gocui.MouseLeft,
|
||||||
Handler: self.onClickMain,
|
Handler: self.onClickMain,
|
||||||
FocusedView: self.context().GetViewName(),
|
FocusedView: self.context().GetViewName(),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
ViewName: "secondary",
|
|
||||||
Key: gocui.MouseLeft,
|
|
||||||
Handler: self.onClickSecondary,
|
|
||||||
FocusedView: self.context().GetViewName(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1188,10 +1176,6 @@ func (self *FilesController) onClickMain(opts gocui.ViewMouseBindingOpts) error
|
|||||||
return self.EnterFile(types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: opts.Y})
|
return self.EnterFile(types.OnFocusOpts{ClickedWindowName: "main", ClickedViewLineIdx: opts.Y})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *FilesController) onClickSecondary(opts gocui.ViewMouseBindingOpts) error {
|
|
||||||
return self.EnterFile(types.OnFocusOpts{ClickedWindowName: "secondary", ClickedViewLineIdx: opts.Y})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (self *FilesController) fetch() error {
|
func (self *FilesController) fetch() error {
|
||||||
return self.c.WithWaitingStatus(self.c.Tr.FetchingStatus, func(task gocui.Task) error {
|
return self.c.WithWaitingStatus(self.c.Tr.FetchingStatus, func(task gocui.Task) error {
|
||||||
if err := self.fetchAux(task); err != nil {
|
if err := self.fetchAux(task); err != nil {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/jesseduffield/gocui"
|
||||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -37,12 +38,41 @@ func (self *SwitchToFocusedMainViewController) GetKeybindings(opts types.Keybind
|
|||||||
return bindings
|
return bindings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *SwitchToFocusedMainViewController) GetMouseKeybindings(opts types.KeybindingsOpts) []*gocui.ViewMouseBinding {
|
||||||
|
return []*gocui.ViewMouseBinding{
|
||||||
|
{
|
||||||
|
ViewName: "main",
|
||||||
|
Key: gocui.MouseLeft,
|
||||||
|
Handler: self.onClickMain,
|
||||||
|
FocusedView: self.context.GetViewName(),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
ViewName: "secondary",
|
||||||
|
Key: gocui.MouseLeft,
|
||||||
|
Handler: self.onClickSecondary,
|
||||||
|
FocusedView: self.context.GetViewName(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (self *SwitchToFocusedMainViewController) Context() types.Context {
|
func (self *SwitchToFocusedMainViewController) Context() types.Context {
|
||||||
return self.context
|
return self.context
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *SwitchToFocusedMainViewController) onClickMain(opts gocui.ViewMouseBindingOpts) error {
|
||||||
|
return self.focusMainView("main")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SwitchToFocusedMainViewController) onClickSecondary(opts gocui.ViewMouseBindingOpts) error {
|
||||||
|
return self.focusMainView("secondary")
|
||||||
|
}
|
||||||
|
|
||||||
func (self *SwitchToFocusedMainViewController) handleFocusMainView() error {
|
func (self *SwitchToFocusedMainViewController) handleFocusMainView() error {
|
||||||
mainViewContext := self.c.Helpers().Window.GetContextForWindow("main")
|
return self.focusMainView("main")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SwitchToFocusedMainViewController) focusMainView(mainViewName string) error {
|
||||||
|
mainViewContext := self.c.Helpers().Window.GetContextForWindow(mainViewName)
|
||||||
mainViewContext.SetParentContext(self.context)
|
mainViewContext.SetParentContext(self.context)
|
||||||
if context, ok := mainViewContext.(types.ISearchableContext); ok {
|
if context, ok := mainViewContext.(types.ISearchableContext); ok {
|
||||||
context.ClearSearchString()
|
context.ClearSearchString()
|
||||||
|
@ -39,7 +39,7 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
// separately)
|
// separately)
|
||||||
// In both views we're going to have 10 lines starting from 'line 1' going down to
|
// In both views we're going to have 10 lines starting from 'line 1' going down to
|
||||||
// 'line 10'.
|
// 'line 10'.
|
||||||
fileContent := ""
|
fileContent := "staged\n"
|
||||||
total := 10
|
total := 10
|
||||||
for i := 1; i <= total; i++ {
|
for i := 1; i <= total; i++ {
|
||||||
remaining := total - i + 1
|
remaining := total - i + 1
|
||||||
@ -47,10 +47,11 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
shell.EmptyCommit(fmt.Sprintf("line %d", remaining))
|
shell.EmptyCommit(fmt.Sprintf("line %d", remaining))
|
||||||
fileContent = fmt.Sprintf("%sline %d\n", fileContent, i)
|
fileContent = fmt.Sprintf("%sline %d\n", fileContent, i)
|
||||||
}
|
}
|
||||||
shell.CreateFile("file1", fileContent)
|
shell.CreateFileAndAdd("file1", "staged\n")
|
||||||
|
shell.UpdateFile("file1", fileContent)
|
||||||
},
|
},
|
||||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||||
assertRangeSelectBehaviour := func(v *ViewDriver, otherView *ViewDriver, lineIdxOfFirstItem int) {
|
assertRangeSelectBehaviour := func(v *ViewDriver, focusOtherView func(), lineIdxOfFirstItem int) {
|
||||||
v.
|
v.
|
||||||
SelectedLines(
|
SelectedLines(
|
||||||
Contains("line 1"),
|
Contains("line 1"),
|
||||||
@ -154,7 +155,7 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Click in view, press shift+arrow -> nonsticky range
|
// Click in view, press shift+arrow -> nonsticky range
|
||||||
otherView.Focus()
|
focusOtherView()
|
||||||
v.Click(1, lineIdxOfFirstItem).
|
v.Click(1, lineIdxOfFirstItem).
|
||||||
SelectedLines(
|
SelectedLines(
|
||||||
Contains("line 1"),
|
Contains("line 1"),
|
||||||
@ -166,7 +167,7 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
assertRangeSelectBehaviour(t.Views().Commits().Focus(), t.Views().Branches(), 0)
|
assertRangeSelectBehaviour(t.Views().Commits().Focus(), func() { t.Views().Branches().Focus() }, 0)
|
||||||
|
|
||||||
t.Views().Files().
|
t.Views().Files().
|
||||||
Focus().
|
Focus().
|
||||||
@ -175,6 +176,6 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
).
|
).
|
||||||
PressEnter()
|
PressEnter()
|
||||||
|
|
||||||
assertRangeSelectBehaviour(t.Views().Staging().IsFocused(), t.Views().Files(), 6)
|
assertRangeSelectBehaviour(t.Views().Staging().IsFocused(), func() { t.Views().Staging().PressTab() }, 6)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user