1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-30 03:23:08 +03:00

Support editing multiple files at once using range selection

We pass all of them to a single editor command, hoping that the editor will be
able to handle multiple files (VS Code and vim do).

We ignore directories that happen to be in the selection range; this makes it
easier to edit multiple files in different folders in tree view. We show an
error if only directories are selected, though.
This commit is contained in:
Stefan Haller
2024-03-20 21:01:20 +01:00
parent 9b5269b490
commit 73019574a8
7 changed files with 69 additions and 30 deletions

View File

@ -2,10 +2,12 @@ package helpers
import (
"path/filepath"
"github.com/samber/lo"
)
type IFilesHelper interface {
EditFile(filename string) error
EditFiles(filenames []string) error
EditFileAtLine(filename string, lineNumber int) error
OpenFile(filename string) error
}
@ -22,12 +24,15 @@ func NewFilesHelper(c *HelperCommon) *FilesHelper {
var _ IFilesHelper = &FilesHelper{}
func (self *FilesHelper) EditFile(filename string) error {
absPath, err := filepath.Abs(filename)
if err != nil {
return err
}
cmdStr, suspend := self.c.Git().File.GetEditCmdStr(absPath)
func (self *FilesHelper) EditFiles(filenames []string) error {
absPaths := lo.Map(filenames, func(filename string, _ int) string {
absPath, err := filepath.Abs(filename)
if err != nil {
return filename
}
return absPath
})
cmdStr, suspend := self.c.Git().File.GetEditCmdStr(absPaths)
return self.callEditor(cmdStr, suspend)
}