From 0a607e26044de634c960b6d1a20680b8cbff052d Mon Sep 17 00:00:00 2001 From: knipferrc Date: Sun, 31 Oct 2021 09:31:41 -0400 Subject: [PATCH] truncate file and allow directories --- dirfs/dirfs.go | 2 +- internal/ui/update.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dirfs/dirfs.go b/dirfs/dirfs.go index 7472b63..900682f 100644 --- a/dirfs/dirfs.go +++ b/dirfs/dirfs.go @@ -456,7 +456,7 @@ func GetDirectoryItemSize(path string) (int64, error) { // WriteToFile writes content to a file. func WriteToFile(path, content string) error { - f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644) if err != nil { return err } diff --git a/internal/ui/update.go b/internal/ui/update.go index 6126ba9..672c695 100644 --- a/internal/ui/update.go +++ b/internal/ui/update.go @@ -658,10 +658,10 @@ func (m *Model) handleEditFileKeyPress(cmds *[]tea.Cmd) { *cmds = append(*cmds, m.handleErrorCmd(err)) } - if !m.showCommandInput && m.primaryPane.GetIsActive() && !selectedFile.IsDir() { + if !m.showCommandInput && m.primaryPane.GetIsActive() { selectionPath := viper.GetString("selection-path") - if selectionPath == "" { + if selectionPath == "" && !selectedFile.IsDir() { editorPath := os.Getenv("EDITOR") if editorPath == "" { *cmds = append(*cmds, m.handleErrorCmd(errors.New("$EDITOR not set")))