mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	Select line that is in the middle of the screen
This commit is contained in:
		| @@ -87,6 +87,14 @@ func (self *MainViewController) Context() types.Context { | ||||
| 	return self.context | ||||
| } | ||||
|  | ||||
| func (self *MainViewController) GetOnFocus() func(types.OnFocusOpts) { | ||||
| 	return func(opts types.OnFocusOpts) { | ||||
| 		if opts.ClickedWindowName != "" { | ||||
| 			self.context.GetView().FocusPoint(0, opts.ClickedViewLineIdx) | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func (self *MainViewController) togglePanel() error { | ||||
| 	if self.otherContext.GetView().Visible { | ||||
| 		self.c.Context().Push(self.otherContext, types.OnFocusOpts{}) | ||||
|   | ||||
| @@ -3,6 +3,7 @@ package controllers | ||||
| import ( | ||||
| 	"github.com/jesseduffield/gocui" | ||||
| 	"github.com/jesseduffield/lazygit/pkg/gui/types" | ||||
| 	"github.com/samber/lo" | ||||
| ) | ||||
|  | ||||
| // This controller is for all contexts that can focus their main view. | ||||
| @@ -61,21 +62,29 @@ 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) | ||||
| 	return self.focusMainView(self.c.Contexts().Normal, -1) | ||||
| } | ||||
|  | ||||
| func (self *SwitchToFocusedMainViewController) focusMainView(mainViewContext types.Context) error { | ||||
| func (self *SwitchToFocusedMainViewController) focusMainView(mainViewContext types.Context, clickedViewLineIdx int) error { | ||||
| 	if context, ok := mainViewContext.(types.ISearchableContext); ok { | ||||
| 		context.ClearSearchString() | ||||
| 	} | ||||
| 	self.c.Context().Push(mainViewContext, types.OnFocusOpts{}) | ||||
| 	onFocusOpts := types.OnFocusOpts{ClickedWindowName: mainViewContext.GetWindowName()} | ||||
| 	if clickedViewLineIdx >= 0 { | ||||
| 		onFocusOpts.ClickedViewLineIdx = clickedViewLineIdx | ||||
| 	} else { | ||||
| 		mainView := mainViewContext.GetView() | ||||
| 		lineIdx := mainView.OriginY() + mainView.Height()/2 | ||||
| 		onFocusOpts.ClickedViewLineIdx = lo.Clamp(lineIdx, 0, mainView.LinesHeight()-1) | ||||
| 	} | ||||
| 	self.c.Context().Push(mainViewContext, onFocusOpts) | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user