Skip to content

Commit 9ad8854

Browse files
committed
Use openDirInEditor when editing a single dir
1 parent e6bd9d0 commit 9ad8854

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pkg/gui/controllers/files_controller.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ func (self *FilesController) GetKeybindings(opts types.KeybindingsOpts) []*types
9090
},
9191
{
9292
Key: opts.GetKey(opts.Config.Universal.Edit),
93-
Handler: self.withItems(self.edit),
94-
GetDisabledReason: self.require(self.itemsSelected(self.canEditFiles)),
93+
Handler: self.withItems(self.editOrOpenDir),
94+
GetDisabledReason: self.any(self.singleItemSelected(), self.itemsSelected(self.canEditFiles)),
9595
Description: self.c.Tr.Edit,
9696
Tooltip: self.c.Tr.EditFileTooltip,
9797
DisplayOnScreen: true,
@@ -913,6 +913,14 @@ func (self *FilesController) edit(nodes []*filetree.FileNode) error {
913913
}))
914914
}
915915

916+
func (self *FilesController) editOrOpenDir(nodes []*filetree.FileNode) error {
917+
if len(nodes) == 1 && !nodes[0].IsFile() {
918+
return self.c.Helpers().Files.OpenDirInEditor(nodes[0].GetPath())
919+
} else {
920+
return self.edit(nodes)
921+
}
922+
}
923+
916924
func (self *FilesController) canEditFiles(nodes []*filetree.FileNode) *types.DisabledReason {
917925
if lo.NoneBy(nodes, func(node *filetree.FileNode) bool { return node.IsFile() }) {
918926
return &types.DisabledReason{

pkg/gui/controllers/list_controller_trait.go

+15
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ func (self *ListControllerTrait[T]) require(callbacks ...func() *types.DisabledR
4444
}
4545
}
4646

47+
// Complement to require - returns nil if any of the provided callbacks return nil.
48+
// If all callbacks return a non-nil DisabledReason, it returns the last one encountered.
49+
func (self *ListControllerTrait[T]) any(callbacks ...func() *types.DisabledReason) func() *types.DisabledReason {
50+
return func() *types.DisabledReason {
51+
var disabledReason *types.DisabledReason
52+
for _, callback := range callbacks {
53+
if disabledReason := callback(); disabledReason == nil {
54+
return disabledReason
55+
}
56+
}
57+
58+
return disabledReason
59+
}
60+
}
61+
4762
// Convenience function for enforcing that a single item is selected.
4863
// Also takes callbacks for additional disabled reasons, and passes the selected
4964
// item into each one.

0 commit comments

Comments
 (0)