mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-16 02:26:24 -04:00
WIP New click behavior
This commit is contained in:
parent
bdf067e172
commit
e520517388
|
|
@ -160,11 +160,8 @@ func (self *MainViewController) toggleSelection() error {
|
|||
v.Highlight = false
|
||||
return nil
|
||||
}
|
||||
v.Highlight = true
|
||||
v.HighlightInactive = false
|
||||
lineIdx := v.OriginY() + v.InnerHeight()/2
|
||||
lineIdx = lo.Clamp(lineIdx, 0, v.ViewLinesHeight()-1)
|
||||
v.FocusPoint(0, lineIdx, false)
|
||||
// Start the selection in the middle of the visible area.
|
||||
showSelectionAtLine(v, v.OriginY()+v.InnerHeight()/2)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -172,14 +169,29 @@ func (self *MainViewController) enter() error {
|
|||
if !self.context.GetView().Highlight {
|
||||
return nil
|
||||
}
|
||||
return self.enterForLine(self.context.GetView().SelectedLineIdx())
|
||||
}
|
||||
|
||||
// enterForLine dives into staging/patch-building for the given line, by
|
||||
// delegating to the side panel beneath the focused main view (the same handler
|
||||
// used when clicking).
|
||||
func (self *MainViewController) enterForLine(lineIdx int) error {
|
||||
sidePanelContext := self.c.Context().NextInStack(self.context)
|
||||
if sidePanelContext != nil && sidePanelContext.GetOnClickFocusedMainView() != nil {
|
||||
return sidePanelContext.GetOnClickFocusedMainView()(
|
||||
self.context.GetViewName(), self.context.GetView().SelectedLineIdx())
|
||||
return sidePanelContext.GetOnClickFocusedMainView()(self.context.GetViewName(), lineIdx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// showSelectionAtLine turns on the focused main view's selection and moves it to
|
||||
// the given view line, clamped to the content.
|
||||
func showSelectionAtLine(view *gocui.View, lineIdx int) {
|
||||
view.Highlight = true
|
||||
view.HighlightInactive = false
|
||||
lineIdx = lo.Clamp(lineIdx, 0, view.ViewLinesHeight()-1)
|
||||
view.FocusPoint(0, lineIdx, false)
|
||||
}
|
||||
|
||||
func (self *MainViewController) editLine() error {
|
||||
if !self.context.GetView().Highlight {
|
||||
return nil
|
||||
|
|
@ -285,23 +297,21 @@ func githubPullRequestLineURL(prURL string, commitSha string, relativePath strin
|
|||
}
|
||||
|
||||
func (self *MainViewController) onClickInAlreadyFocusedView(opts gocui.ViewMouseBindingOpts) error {
|
||||
if self.context.GetView().Highlight && !opts.IsDoubleClick {
|
||||
return nil
|
||||
}
|
||||
|
||||
sidePanelContext := self.c.Context().NextInStack(self.context)
|
||||
if sidePanelContext != nil && sidePanelContext.GetOnClickFocusedMainView() != nil {
|
||||
return sidePanelContext.GetOnClickFocusedMainView()(self.context.GetViewName(), opts.Y)
|
||||
// A click points at a line, so it sets the selection there; a double-click
|
||||
// additionally dives into staging/patch-building for that line.
|
||||
showSelectionAtLine(self.context.GetView(), opts.Y)
|
||||
if opts.IsDoubleClick {
|
||||
return self.enterForLine(opts.Y)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *MainViewController) onClickInOtherViewOfMainViewPair(opts gocui.ViewMouseBindingOpts) error {
|
||||
self.c.Context().Push(self.context, types.OnFocusOpts{
|
||||
ClickedWindowName: self.context.GetWindowName(),
|
||||
ClickedViewLineIdx: opts.Y,
|
||||
})
|
||||
|
||||
self.c.Context().Push(self.context, types.OnFocusOpts{})
|
||||
showSelectionAtLine(self.context.GetView(), opts.Y)
|
||||
if opts.IsDoubleClick {
|
||||
return self.enterForLine(opts.Y)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,21 +61,27 @@ func (self *SwitchToFocusedMainViewController) Context() types.Context {
|
|||
}
|
||||
|
||||
func (self *SwitchToFocusedMainViewController) onClickMain(opts gocui.ViewMouseBindingOpts) error {
|
||||
return self.focusMainView(self.c.Contexts().Normal)
|
||||
return self.focusMainView(self.c.Contexts().Normal, opts.Y)
|
||||
}
|
||||
|
||||
func (self *SwitchToFocusedMainViewController) onClickSecondary(opts gocui.ViewMouseBindingOpts) error {
|
||||
return self.focusMainView(self.c.Contexts().NormalSecondary)
|
||||
return self.focusMainView(self.c.Contexts().NormalSecondary, opts.Y)
|
||||
}
|
||||
|
||||
func (self *SwitchToFocusedMainViewController) handleFocusMainView() error {
|
||||
return self.focusMainView(self.c.Contexts().Normal)
|
||||
// Focusing by keyboard doesn't point at any particular line, so we don't
|
||||
// show a selection; the user is free to scroll. Clicking does point at a
|
||||
// line, so it selects it (see focusMainView's clickedLineIdx).
|
||||
return self.focusMainView(self.c.Contexts().Normal, -1)
|
||||
}
|
||||
|
||||
func (self *SwitchToFocusedMainViewController) focusMainView(mainViewContext types.Context) error {
|
||||
func (self *SwitchToFocusedMainViewController) focusMainView(mainViewContext types.Context, clickedLineIdx int) error {
|
||||
if context, ok := mainViewContext.(types.ISearchableContext); ok {
|
||||
context.ClearSearchString()
|
||||
}
|
||||
self.c.Context().Push(mainViewContext, types.OnFocusOpts{})
|
||||
if clickedLineIdx >= 0 {
|
||||
showSelectionAtLine(mainViewContext.GetView(), clickedLineIdx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue