Fix buffer name problem

Fixes #458
This commit is contained in:
Zachary Yedidia
2016-11-19 19:07:51 -05:00
parent c692570212
commit 0fbae7610c
7 changed files with 15 additions and 11 deletions

View File

@@ -740,7 +740,7 @@ func (v *View) SaveAs(usePlugin bool) bool {
// the filename might or might not be quoted, so unquote first then join the strings.
filename = strings.Join(SplitCommandArgs(filename), " ")
v.Buf.Path = filename
v.Buf.Name = filename
v.Buf.name = filename
v.Save(true)
}

View File

@@ -30,7 +30,7 @@ type Buffer struct {
// Absolute path to the file on disk
AbsPath string
// Name of the buffer on the status line
Name string
name string
// Whether or not the buffer has been modified since it was opened
IsModified bool
@@ -164,6 +164,13 @@ func NewBuffer(txt []byte, path string) *Buffer {
return b
}
func (b *Buffer) GetName() string {
if b.name == "" {
return b.Path
}
return b.name
}
// UpdateRules updates the syntax rules and filetype for this buffer
// This is called when the colorscheme changes
func (b *Buffer) UpdateRules() {

View File

@@ -79,7 +79,7 @@ func (m *Messenger) AddLog(msg string) {
func (m *Messenger) getBuffer() *Buffer {
if m.log == nil {
m.log = NewBuffer([]byte{}, "")
m.log.Name = "Log"
m.log.name = "Log"
}
return m.log
}

View File

@@ -231,7 +231,7 @@ func (s *SplitTree) ResizeSplits() {
}
func (l *LeafNode) String() string {
return l.view.Buf.Name
return l.view.Buf.GetName()
}
func search(haystack []Node, needle Node) int {

View File

@@ -17,10 +17,7 @@ func (sline *Statusline) Display() {
// We'll draw the line at the lowest line in the view
y := sline.view.height + sline.view.y
file := sline.view.Buf.Name
if file == "" {
file = sline.view.Buf.Path
}
file := sline.view.Buf.GetName()
// If the buffer is dirty (has been modified) write a little '+'
if sline.view.Buf.IsModified {

View File

@@ -85,7 +85,7 @@ func TabbarString() (string, map[int]int) {
} else {
str += " "
}
str += t.views[t.curView].Buf.Name
str += t.views[t.curView].Buf.GetName()
if i == curTab {
str += "]"
} else {

View File

@@ -200,7 +200,7 @@ func (v *View) CanClose() bool {
if v.Buf.Settings["autosave"].(bool) {
char = 'y'
} else {
char, canceled = messenger.LetterPrompt("Save changes to "+v.Buf.Name+" before closing? (y,n,esc) ", 'y', 'n')
char, canceled = messenger.LetterPrompt("Save changes to "+v.Buf.GetName()+" before closing? (y,n,esc) ", 'y', 'n')
}
if !canceled {
if char == 'y' {
@@ -617,7 +617,7 @@ func (v *View) openHelp(helpPage string) {
TermMessage("Unable to load help text", helpPage, "\n", err)
} else {
helpBuffer := NewBuffer(data, helpPage+".md")
helpBuffer.Name = "Help"
helpBuffer.name = "Help"
if v.Type == vtHelp {
v.OpenBuffer(helpBuffer)