summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2024-01-25 08:56:10 +0100
committerStefan Haller <stefan@haller-berlin.de>2024-01-25 08:56:10 +0100
commit12500be5545f6835accc54a51770532dd8d37d1a (patch)
tree51ddbea3db444d15bb567c4413136202df2266a7
parent05b97c8c8ebb12f633aac38d726f87dce1e2b45b (diff)
Pass absolute file paths to all editor commands
This helps work around bugs in editors that may get confused about relative paths (like nvim-remote, see https://github.com/neovim/neovim/issues/18519), and shouldn't have any negative effect on others.
-rw-r--r--pkg/gui/controllers/helpers/files_helper.go34
1 files changed, 29 insertions, 5 deletions
diff --git a/pkg/gui/controllers/helpers/files_helper.go b/pkg/gui/controllers/helpers/files_helper.go
index 140a71127..35cd9d0c9 100644
--- a/pkg/gui/controllers/helpers/files_helper.go
+++ b/pkg/gui/controllers/helpers/files_helper.go
@@ -1,5 +1,9 @@
package helpers
+import (
+ "path/filepath"
+)
+
type IFilesHelper interface {
EditFile(filename string) error
EditFileAtLine(filename string, lineNumber int) error
@@ -19,17 +23,29 @@ func NewFilesHelper(c *HelperCommon) *FilesHelper {
var _ IFilesHelper = &FilesHelper{}
func (self *FilesHelper) EditFile(filename string) error {
- cmdStr, suspend := self.c.Git().File.GetEditCmdStr(filename)
+ absPath, err := filepath.Abs(filename)
+ if err != nil {
+ return err
+ }
+ cmdStr, suspend := self.c.Git().File.GetEditCmdStr(absPath)
return self.callEditor(cmdStr, suspend)
}
func (self *FilesHelper) EditFileAtLine(filename string, lineNumber int) error {
- cmdStr, suspend := self.c.Git().File.GetEditAtLineCmdStr(filename, lineNumber)
+ absPath, err := filepath.Abs(filename)
+ if err != nil {
+ return err
+ }
+ cmdStr, suspend := self.c.Git().File.GetEditAtLineCmdStr(absPath, lineNumber)
return self.callEditor(cmdStr, suspend)
}
func (self *FilesHelper) EditFileAtLineAndWait(filename string, lineNumber int) error {
- cmdStr := self.c.Git().File.GetEditAtLineAndWaitCmdStr(filename, lineNumber)
+ absPath, err := filepath.Abs(filename)
+ if err != nil {
+ return err
+ }
+ cmdStr := self.c.Git().File.GetEditAtLineAndWaitCmdStr(absPath, lineNumber)
// Always suspend, regardless of the value of the suspend config,
// since we want to prevent interacting with the UI until the editor
@@ -38,7 +54,11 @@ func (self *FilesHelper) EditFileAtLineAndWait(filename string, lineNumber int)
}
func (self *FilesHelper) OpenDirInEditor(path string) error {
- cmdStr, suspend := self.c.Git().File.GetOpenDirInEditorCmdStr(path)
+ absPath, err := filepath.Abs(path)
+ if err != nil {
+ return err
+ }
+ cmdStr, suspend := self.c.Git().File.GetOpenDirInEditorCmdStr(absPath)
return self.callEditor(cmdStr, suspend)
}
@@ -54,8 +74,12 @@ func (self *FilesHelper) callEditor(cmdStr string, suspend bool) error {
}
func (self *FilesHelper) OpenFile(filename string) error {
+ absPath, err := filepath.Abs(filename)
+ if err != nil {
+ return err
+ }
self.c.LogAction(self.c.Tr.Actions.OpenFile)
- if err := self.c.OS().OpenFile(filename); err != nil {
+ if err := self.c.OS().OpenFile(absPath); err != nil {
return self.c.Error(err)
}
return nil