mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-05 06:30:28 +09:00
Refactor ReOpen function
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user