diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index 1a02ddd6..ebf98b28 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -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) } diff --git a/cmd/micro/buffer.go b/cmd/micro/buffer.go index 8be7433d..9bdc1250 100644 --- a/cmd/micro/buffer.go +++ b/cmd/micro/buffer.go @@ -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() { diff --git a/cmd/micro/messenger.go b/cmd/micro/messenger.go index 36c1a6e0..5287832e 100644 --- a/cmd/micro/messenger.go +++ b/cmd/micro/messenger.go @@ -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 } diff --git a/cmd/micro/split_tree.go b/cmd/micro/split_tree.go index 66c85eb0..8fd98b26 100644 --- a/cmd/micro/split_tree.go +++ b/cmd/micro/split_tree.go @@ -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 { diff --git a/cmd/micro/statusline.go b/cmd/micro/statusline.go index 67d81c77..c2af51ba 100644 --- a/cmd/micro/statusline.go +++ b/cmd/micro/statusline.go @@ -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 { diff --git a/cmd/micro/tab.go b/cmd/micro/tab.go index 985e1d50..c981e072 100644 --- a/cmd/micro/tab.go +++ b/cmd/micro/tab.go @@ -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 { diff --git a/cmd/micro/view.go b/cmd/micro/view.go index 8bdff81d..183f6d4e 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -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)