mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
Extract a function HandleGenericClick
This commit is contained in:
@ -79,18 +79,7 @@ func (self *StatusController) GetMouseKeybindings(opts types.KeybindingsOpts) []
|
||||
}
|
||||
|
||||
func (self *StatusController) onClickMain(opts gocui.ViewMouseBindingOpts) error {
|
||||
view := self.c.Views().Main
|
||||
|
||||
cx, cy := view.Cursor()
|
||||
url, err := view.Word(cx, cy)
|
||||
if err == nil && strings.HasPrefix(url, "https://") {
|
||||
// Ignore errors (opening the link via the OS can fail if the
|
||||
// `os.openLink` config key references a command that doesn't exist, or
|
||||
// that errors when called.)
|
||||
_ = self.c.OS().OpenLink(url)
|
||||
}
|
||||
|
||||
return nil
|
||||
return self.c.HandleGenericClick(self.c.Views().Main)
|
||||
}
|
||||
|
||||
func (self *StatusController) GetOnRenderToMain() func() error {
|
||||
|
@ -33,6 +33,10 @@ func (self *guiCommon) PostRefreshUpdate(context types.Context) error {
|
||||
return self.gui.postRefreshUpdate(context)
|
||||
}
|
||||
|
||||
func (self *guiCommon) HandleGenericClick(view *gocui.View) error {
|
||||
return self.gui.handleGenericClick(view)
|
||||
}
|
||||
|
||||
func (self *guiCommon) RunSubprocessAndRefresh(cmdObj oscommands.ICmdObj) error {
|
||||
return self.gui.runSubprocessWithSuspenseAndRefresh(cmdObj)
|
||||
}
|
||||
|
@ -35,6 +35,10 @@ type IGuiCommon interface {
|
||||
// case would be overkill, although refresh will internally call 'PostRefreshUpdate'
|
||||
PostRefreshUpdate(Context) error
|
||||
|
||||
// a generic click handler that can be used for any view; it handles opening
|
||||
// URLs in the browser when the user clicks on one
|
||||
HandleGenericClick(view *gocui.View) error
|
||||
|
||||
// renders string to a view without resetting its origin
|
||||
SetViewContent(view *gocui.View, content string)
|
||||
// resets cursor and origin of view. Often used before calling SetViewContent
|
||||
|
@ -1,6 +1,7 @@
|
||||
package gui
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jesseduffield/gocui"
|
||||
@ -148,3 +149,18 @@ func (gui *Gui) postRefreshUpdate(c types.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// handleGenericClick is a generic click handler that can be used for any view.
|
||||
// It handles opening URLs in the browser when the user clicks on one.
|
||||
func (gui *Gui) handleGenericClick(view *gocui.View) error {
|
||||
cx, cy := view.Cursor()
|
||||
url, err := view.Word(cx, cy)
|
||||
if err == nil && strings.HasPrefix(url, "https://") {
|
||||
// Ignore errors (opening the link via the OS can fail if the
|
||||
// `os.openLink` config key references a command that doesn't exist, or
|
||||
// that errors when called.)
|
||||
_ = gui.c.OS().OpenLink(url)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user