diff --git a/cmd/micro/buffer.go b/cmd/micro/buffer.go index a968aaed..c74ee3b7 100644 --- a/cmd/micro/buffer.go +++ b/cmd/micro/buffer.go @@ -140,28 +140,33 @@ func (b *Buffer) CheckModTime() { b.ModTime, _ = GetModTime(b.Path) } else { // Load new changes - data, err := ioutil.ReadFile(b.Path) - txt := string(data) - - if err != nil { - messenger.Error(err.Error()) - return - } - if txt == "" { - b.r = new(rope.Rope) - } else { - b.r = rope.New(txt) - } - - b.ModTime, _ = GetModTime(b.Path) - b.Cursor.Relocate() - b.IsModified = false - b.Update() + b.ReOpen() } } } } +// ReOpen reloads the current buffer from disk +func (b *Buffer) ReOpen() { + data, err := ioutil.ReadFile(b.Path) + txt := string(data) + + if err != nil { + messenger.Error(err.Error()) + return + } + if txt == "" { + b.r = new(rope.Rope) + } else { + b.r = rope.New(txt) + } + + b.ModTime, _ = GetModTime(b.Path) + b.Cursor.Relocate() + b.IsModified = false + b.Update() +} + // Update fetches the string from the rope and updates the `text` and `lines` in the buffer func (b *Buffer) Update() { b.Lines = strings.Split(b.String(), "\n") diff --git a/cmd/micro/view.go b/cmd/micro/view.go index a2c7713f..343e9f6e 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -1,7 +1,6 @@ package main import ( - "io/ioutil" "reflect" "runtime" "strconv" @@ -192,20 +191,7 @@ func (v *View) CloseBuffer() { // ReOpen reloads the current buffer func (v *View) ReOpen() { if v.CanClose("Continue? (yes, no, save) ") { - file, err := ioutil.ReadFile(v.Buf.Path) - filename := v.Buf.Name - - if err != nil { - messenger.Error(err.Error()) - return - } - buf := NewBuffer(string(file), filename) - v.Buf = buf - v.Cursor.Relocate() - buf.Cursor.Goto(*v.Cursor) - v.Cursor = &buf.Cursor - v.matches = Match(v) - v.Relocate() + v.Buf.ReOpen() } }