Open file on unspecified line

This commit is contained in:
Luka Markušić 2023-02-03 11:07:42 +01:00
parent 16802a048e
commit 936ae69429
2 changed files with 24 additions and 2 deletions

View file

@ -27,7 +27,7 @@ func (self *FileCommands) Cat(fileName string) (string, error) {
return string(buf), nil
}
func (self *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, error) {
func (self *FileCommands) GetEditor() (string, error) {
editor := self.UserConfig.OS.EditCommand
if editor == "" {
@ -50,6 +50,14 @@ func (self *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string
if editor == "" {
return "", errors.New("No editor defined in config file, $GIT_EDITOR, $VISUAL, $EDITOR, or git config")
}
return editor, nil
}
func (self *FileCommands) GetEditCmdStr(filename string, lineNumber int) (string, error) {
editor, err := self.GetEditor()
if err != nil {
return "", err
}
templateValues := map[string]string{
"editor": editor,

View file

@ -34,7 +34,21 @@ func NewFilesHelper(
var _ IFilesHelper = &FilesHelper{}
func (self *FilesHelper) EditFile(filename string) error {
return self.EditFileAtLine(filename, 1)
editor, err := self.git.File.GetEditor()
if err != nil {
return self.c.Error(err)
}
editCmd := ""
switch editor {
case "code":
editCmd = editor + " -r --goto -- " + filename
default:
editCmd = editor + " -- " + filename
}
self.c.LogAction(self.c.Tr.Actions.EditFile)
return self.c.RunSubprocessAndRefresh(
self.os.Cmd.NewShell(editCmd),
)
}
func (self *FilesHelper) EditFileAtLine(filename string, lineNumber int) error {