mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-12 12:55: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"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -359,6 +360,28 @@ func (gui *Gui) onNewRepo(startArgs appTypes.StartArgs, contextKey types.Context
|
||||||
return nil
|
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 a context key has been given, push that instead, and set its index to 0
|
||||||
if contextKey != context.NO_CONTEXT {
|
if contextKey != context.NO_CONTEXT {
|
||||||
contextToPush = gui.c.ContextForKey(contextKey)
|
contextToPush = gui.c.ContextForKey(contextKey)
|
||||||
|
|
|
@ -784,7 +784,9 @@ type TranslationSet struct {
|
||||||
MarkAsBaseCommit string
|
MarkAsBaseCommit string
|
||||||
MarkAsBaseCommitTooltip string
|
MarkAsBaseCommitTooltip string
|
||||||
MarkedCommitMarker string
|
MarkedCommitMarker string
|
||||||
|
FailedToOpenURL string
|
||||||
PleaseGoToURL string
|
PleaseGoToURL string
|
||||||
|
InvalidLazygitEditURL string
|
||||||
NoCopiedCommits string
|
NoCopiedCommits string
|
||||||
DisabledMenuItemPrefix string
|
DisabledMenuItemPrefix string
|
||||||
QuickStartInteractiveRebase string
|
QuickStartInteractiveRebase string
|
||||||
|
@ -1770,7 +1772,9 @@ func EnglishTranslationSet() *TranslationSet {
|
||||||
MarkAsBaseCommit: "Mark as base commit for rebase",
|
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.",
|
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 ↑↑↑",
|
MarkedCommitMarker: "↑↑↑ Will rebase from here ↑↑↑",
|
||||||
|
FailedToOpenURL: "Failed to open URL %s\n\nError: %v",
|
||||||
PleaseGoToURL: "Please go to {{.url}}",
|
PleaseGoToURL: "Please go to {{.url}}",
|
||||||
|
InvalidLazygitEditURL: "Invalid lazygit-edit URL format: %s",
|
||||||
DisabledMenuItemPrefix: "Disabled: ",
|
DisabledMenuItemPrefix: "Disabled: ",
|
||||||
NoCopiedCommits: "No copied commits",
|
NoCopiedCommits: "No copied commits",
|
||||||
QuickStartInteractiveRebase: "Start interactive rebase",
|
QuickStartInteractiveRebase: "Start interactive rebase",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue