From d47e4070634cc93185cae8d3efc022fef6e4bdf5 Mon Sep 17 00:00:00 2001 From: "Luke I. Wilson" Date: Wed, 24 Mar 2021 17:47:13 -0500 Subject: [PATCH] Fixed bug in saving files: was missing os.O_TRUNC bit flag --- main.go | 4 ++-- ui/buffer/rope_test.go | 11 ----------- ui/textedit.go | 1 - 3 files changed, 2 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 4d75595..42b67fa 100644 --- a/main.go +++ b/main.go @@ -129,7 +129,7 @@ func main() { tab := tabContainer.GetTab(tabContainer.GetSelectedTabIdx()) te := tab.Child.(*ui.TextEdit) if len(te.FilePath) > 0 { - f, err := os.OpenFile(te.FilePath, os.O_WRONLY|os.O_CREATE, fs.ModePerm) + f, err := os.OpenFile(te.FilePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, fs.ModePerm) if err != nil { panic(err) } @@ -312,7 +312,7 @@ func main() { s.Sync() // Redraw everything case *tcell.EventKey: // On Escape, we change focus between editor and the MenuBar. - if dialog == nil { // While no dialog is present... + if dialog == nil { if ev.Key() == tcell.KeyEscape { if focusedComponent == tabContainer { changeFocus(menuBar) diff --git a/ui/buffer/rope_test.go b/ui/buffer/rope_test.go index 5a8e14b..0e64728 100644 --- a/ui/buffer/rope_test.go +++ b/ui/buffer/rope_test.go @@ -16,17 +16,6 @@ func TestRopeInserting(t *testing.T) { t.Errorf("string does not match \"withtext\", got %#v", str) t.Fail() } - - //withtext - // - - // Note the inclusive bounds and pointing to last line, first column. - buf.Remove(0, 0, 1, 0) // Delete all of the buffer - - if str := string(buf.Bytes()); str != "" { - t.Errorf("string does not math \"\", got %#v", str) - t.Fail() - } } func TestRopeBounds(t *testing.T) { diff --git a/ui/textedit.go b/ui/textedit.go index a3faebd..050b6a1 100644 --- a/ui/textedit.go +++ b/ui/textedit.go @@ -113,7 +113,6 @@ func (t *TextEdit) Delete(forwards bool) { t.Dirty = true if t.selectMode { // If text is selected, delete the whole selection - t.cury, t.curx = t.Buffer.ClampLineCol(t.selection.EndLine, t.selection.EndCol) t.selectMode = false // Disable selection and prevent infinite loop // Delete the region