From 430effb51cb0ac59a606483b693c55ef56655659 Mon Sep 17 00:00:00 2001 From: Hizkia Felix Winata Date: Fri, 20 Sep 2024 14:48:14 +0800 Subject: [PATCH] fix: write to a different file --- internal/display/key_command.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/display/key_command.go b/internal/display/key_command.go index a33cd37..eb3699d 100644 --- a/internal/display/key_command.go +++ b/internal/display/key_command.go @@ -23,12 +23,20 @@ func handleCommand(m Model, command string, args []string) (Model, tea.Cmd) { case "w", "write", "wq": // Save the buffer fileName := m.eb.Name + overwrite := true if len(args) > 0 { fileName = args[0] + overwrite = false } saveCmd := func() tea.Msg { - n, err := m.eb.Save(fileName) + var n int64 + var err error + if overwrite { + n, err = m.eb.Save(fileName) + } else { + n, err = m.eb.WriteToFile(fileName) + } if err != nil { return StatusTextMsg{Text: "Error saving: " + err.Error(), Error: true} }