diff --git a/pkg/commands/models/status_line_node.go b/pkg/commands/models/status_line_node.go index 1a2471935..e0a9051e2 100644 --- a/pkg/commands/models/status_line_node.go +++ b/pkg/commands/models/status_line_node.go @@ -203,3 +203,11 @@ func (s *StatusLineNode) GetPathsMatching(test func(*StatusLineNode) bool) []str return paths } + +func (s *StatusLineNode) ID() string { + return s.GetPath() +} + +func (s *StatusLineNode) Description() string { + return s.GetPath() +} diff --git a/pkg/gui/custom_commands.go b/pkg/gui/custom_commands.go index 6b86b07fd..f1fadeb5f 100644 --- a/pkg/gui/custom_commands.go +++ b/pkg/gui/custom_commands.go @@ -16,6 +16,7 @@ type CustomCommandObjects struct { SelectedReflogCommit *models.Commit SelectedSubCommit *models.Commit SelectedFile *models.File + SelectedPath string SelectedLocalBranch *models.Branch SelectedRemoteBranch *models.RemoteBranch SelectedRemote *models.Remote @@ -29,6 +30,7 @@ type CustomCommandObjects struct { func (gui *Gui) resolveTemplate(templateStr string, promptResponses []string) (string, error) { objects := CustomCommandObjects{ SelectedFile: gui.getSelectedFile(), + SelectedPath: gui.getSelectedPath(), SelectedLocalCommit: gui.getSelectedLocalCommit(), SelectedReflogCommit: gui.getSelectedReflogCommit(), SelectedLocalBranch: gui.getSelectedBranch(), diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index d443a7a8f..772b05cf3 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -43,6 +43,15 @@ func (gui *Gui) getSelectedFile() *models.File { return node.File } +func (gui *Gui) getSelectedPath() string { + node := gui.getSelectedStatusNode() + if node == nil { + return "" + } + + return node.GetPath() +} + func (gui *Gui) selectFile(alreadySelected bool) error { gui.getFilesView().FocusPoint(0, gui.State.Panels.Files.SelectedLineIdx) @@ -104,7 +113,7 @@ func (gui *Gui) refreshFilesAndSubmodules() error { gui.Mutexes.RefreshingFilesMutex.Unlock() }() - selectedFile := gui.getSelectedFile() + selectedPath := gui.getSelectedPath() filesView := gui.getFilesView() if filesView == nil { @@ -131,8 +140,8 @@ func (gui *Gui) refreshFilesAndSubmodules() error { } if gui.currentContext().GetKey() == FILES_CONTEXT_KEY || (g.CurrentView() == gui.getMainView() && g.CurrentView().Context == MAIN_MERGING_CONTEXT_KEY) { - newSelectedFile := gui.getSelectedFile() - alreadySelected := selectedFile != nil && newSelectedFile != nil && newSelectedFile.Name == selectedFile.Name + newSelectedPath := gui.getSelectedPath() + alreadySelected := selectedPath != "" && newSelectedPath == selectedPath if err := gui.selectFile(alreadySelected); err != nil { return err } @@ -461,20 +470,25 @@ func (gui *Gui) editFile(filename string) error { } func (gui *Gui) handleFileEdit(g *gocui.Gui, v *gocui.View) error { - file := gui.getSelectedFile() - if file == nil { + node := gui.getSelectedStatusNode() + if node == nil { return nil } - return gui.editFile(file.Name) + if node.File == nil { + return gui.createErrorPanel(gui.Tr.ErrCannotEditDirectory) + } + + return gui.editFile(node.GetPath()) } func (gui *Gui) handleFileOpen(g *gocui.Gui, v *gocui.View) error { - file := gui.getSelectedFile() - if file == nil { + node := gui.getSelectedStatusNode() + if node == nil { return nil } - return gui.openFile(file.Name) + + return gui.openFile(node.GetPath()) } func (gui *Gui) handleRefreshFiles(g *gocui.Gui, v *gocui.View) error { diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index 7a7c6a8e8..748813f4f 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -278,10 +278,11 @@ func (gui *Gui) filesListContext() *ListContext { return mappedLines + // TODO: Fix this up return presentation.GetFileListDisplayStrings(gui.State.StatusLineManager.GetAllFiles(), gui.State.Modes.Diffing.Ref, gui.State.Submodules) }, SelectedItem: func() (ListItem, bool) { - item := gui.getSelectedFile() + item := gui.getSelectedStatusNode() return item, item != nil }, } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index aa2460214..4862f80ae 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -435,6 +435,7 @@ type TranslationSet struct { PullRequestURLCopiedToClipboard string CommitMessageCopiedToClipboard string LcCopiedToClipboard string + ErrCannotEditDirectory string } const englishReleaseNotes = `## lazygit 0.26 Release Notes @@ -993,5 +994,6 @@ func englishTranslationSet() TranslationSet { PullRequestURLCopiedToClipboard: "Pull request URL copied to clipboard", CommitMessageCopiedToClipboard: "Commit message copied to clipboard", LcCopiedToClipboard: "copied to clipboard", + ErrCannotEditDirectory: "Cannot edit directory: you can only edit individual files", } }