mirror of
				https://github.com/jesseduffield/lazygit.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	Make HandleGenericClick a little smarter
Make it recognize URLs wrapped in angle brackets, and followed by punktuation. We don't need this for the status panel, but we will need it for confirmation panels.
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| package gui | ||||
|  | ||||
| import ( | ||||
| 	"strings" | ||||
| 	"regexp" | ||||
| 	"time" | ||||
|  | ||||
| 	"github.com/jesseduffield/gocui" | ||||
| @@ -154,13 +154,23 @@ func (gui *Gui) postRefreshUpdate(c types.Context) error { | ||||
| // 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) | ||||
| 	word, err := view.Word(cx, cy) | ||||
| 	if err != nil { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	// Allow URLs to be wrapped in angle brackets, and the closing bracket to | ||||
| 	// be followed by punctuation: | ||||
| 	re := regexp.MustCompile(`^<?(https://.+?)(>[,.;!]*)?$`) | ||||
| 	matches := re.FindStringSubmatch(word) | ||||
| 	if matches == nil { | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	// 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(matches[1]) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user