From 936ae69429aa48b61cc9da878544c014c8288bf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Marku=C5=A1i=C4=87?= Date: Fri, 3 Feb 2023 11:07:42 +0100 Subject: [PATCH] Open file on unspecified line --- pkg/commands/git_commands/file.go | 10 +++++++++- pkg/gui/controllers/helpers/files_helper.go | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/pkg/commands/git_commands/file.go b/pkg/commands/git_commands/file.go index 111733bb7..630c10374 100644 --- a/pkg/commands/git_commands/file.go +++ b/pkg/commands/git_commands/file.go @@ -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, diff --git a/pkg/gui/controllers/helpers/files_helper.go b/pkg/gui/controllers/helpers/files_helper.go index 72be6e4e5..c3c1737e5 100644 --- a/pkg/gui/controllers/helpers/files_helper.go +++ b/pkg/gui/controllers/helpers/files_helper.go @@ -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 {