mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-11 12:25:47 +02:00
Set an openHyperlink function on gocui
This commit is contained in:
parent
250eb14de1
commit
e1acb6a547
2 changed files with 27 additions and 0 deletions
|
@ -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)
|
||||
|
|
|
@ -784,7 +784,9 @@ type TranslationSet struct {
|
|||
MarkAsBaseCommit string
|
||||
MarkAsBaseCommitTooltip string
|
||||
MarkedCommitMarker string
|
||||
FailedToOpenURL string
|
||||
PleaseGoToURL string
|
||||
InvalidLazygitEditURL string
|
||||
NoCopiedCommits string
|
||||
DisabledMenuItemPrefix string
|
||||
QuickStartInteractiveRebase string
|
||||
|
@ -1770,7 +1772,9 @@ func EnglishTranslationSet() *TranslationSet {
|
|||
MarkAsBaseCommit: "Mark as base commit for rebase",
|
||||
MarkAsBaseCommitTooltip: "Select a base commit for the next rebase. When you rebase onto a branch, only commits above the base commit will be brought across. This uses the `git rebase --onto` command.",
|
||||
MarkedCommitMarker: "↑↑↑ Will rebase from here ↑↑↑",
|
||||
FailedToOpenURL: "Failed to open URL %s\n\nError: %v",
|
||||
PleaseGoToURL: "Please go to {{.url}}",
|
||||
InvalidLazygitEditURL: "Invalid lazygit-edit URL format: %s",
|
||||
DisabledMenuItemPrefix: "Disabled: ",
|
||||
NoCopiedCommits: "No copied commits",
|
||||
QuickStartInteractiveRebase: "Start interactive rebase",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue