mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Set an openHyperlink function on gocui
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -359,6 +360,28 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
|
||||
return nil
|
||||
})
|
||||
|
||||
gui.g.SetOpenHyperlinkFunc(func(url string) error {
|
||||
if strings.HasPrefix(url, "lazygit-edit:") {
|
||||
re := regexp.MustCompile(`^lazygit-edit://(.+?)(?::(\d+))?$`)
|
||||
matches := re.FindStringSubmatch(url)
|
||||
if matches == nil {
|
||||
return fmt.Errorf(gui.Tr.InvalidLazygitEditURL, url)
|
||||
}
|
||||
filepath := matches[1]
|
||||
if matches[2] != "" {
|
||||
lineNumber := utils.MustConvertToInt(matches[2])
|
||||
return gui.helpers.Files.EditFileAtLine(filepath, lineNumber)
|
||||
}
|
||||
return gui.helpers.Files.EditFiles([]string{filepath})
|
||||
}
|
||||
|
||||
if err := gui.os.OpenLink(url); err != nil {
|
||||
return fmt.Errorf(gui.Tr.FailedToOpenURL, url, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
// if a context key has been given, push that instead, and set its index to 0
|
||||
if contextKey != context.NO_CONTEXT {
|
||||
contextToPush = gui.c.ContextForKey(contextKey)
|
||||
|
Reference in New Issue
Block a user