From 02f78edaf9bcc7516f724911fc623d8385398fd9 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Thu, 14 Jul 2016 13:01:02 -0400 Subject: [PATCH] Open help in a separate split --- cmd/micro/actions.go | 15 +++++---------- cmd/micro/buffer.go | 1 - cmd/micro/statusline.go | 2 +- cmd/micro/view.go | 12 +++--------- 4 files changed, 9 insertions(+), 21 deletions(-) diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index d732a263..b8418d1a 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -327,7 +327,7 @@ func (v *View) InsertTab() bool { // Save the buffer to disk func (v *View) Save() bool { - if v.helpOpen { + if v.Help { // We can't save the help text return false } @@ -651,15 +651,13 @@ func (v *View) ClearStatus() bool { // ToggleHelp toggles the help screen func (v *View) ToggleHelp() bool { - if !v.helpOpen { - v.lastBuffer = v.Buf + if !CurView().Help { helpBuffer := NewBuffer([]byte(helpTxt), "help.md") helpBuffer.Name = "Help" - v.helpOpen = true - v.OpenBuffer(helpBuffer) + v.HSplit(helpBuffer) + CurView().Help = true } else { - v.OpenBuffer(v.lastBuffer) - v.helpOpen = false + v.Quit() } return true } @@ -688,9 +686,6 @@ func (v *View) CommandMode() bool { // is the last view // However, since micro only supports one view for now, it doesn't really matter func (v *View) Quit() bool { - if v.helpOpen { - return v.ToggleHelp() - } // Make sure not to quit if there are unsaved changes if v.CanClose("Quit anyway? (yes, no, save) ") { v.CloseBuffer() diff --git a/cmd/micro/buffer.go b/cmd/micro/buffer.go index 9e40f55e..17abf531 100644 --- a/cmd/micro/buffer.go +++ b/cmd/micro/buffer.go @@ -189,7 +189,6 @@ func (b *Buffer) Serialize() error { b.Cursor, b.ModTime, }) - // err = enc.Encode(b.Cursor) } file.Close() return err diff --git a/cmd/micro/statusline.go b/cmd/micro/statusline.go index 0c72f517..6ed86362 100644 --- a/cmd/micro/statusline.go +++ b/cmd/micro/statusline.go @@ -37,7 +37,7 @@ func (sline *Statusline) Display() { file += " " + sline.view.Buf.FileType rightText := helpBinding + " for help " - if sline.view.helpOpen { + if sline.view.Help { rightText = helpBinding + " to close help " } diff --git a/cmd/micro/view.go b/cmd/micro/view.go index da6c978b..53de9437 100644 --- a/cmd/micro/view.go +++ b/cmd/micro/view.go @@ -27,6 +27,9 @@ type View struct { widthPercent int heightPercent int + // Specifies whether or not this view holds a help buffer + Help bool + // Actual with and height width int height int @@ -40,22 +43,13 @@ type View struct { // Holds the list of gutter messages messages map[string][]GutterMessage - // Is the help text opened in this view - helpOpen bool - // This is the index of this view in the views array Num int // What tab is this view stored in TabNum int - // Is this view modifiable? - Modifiable bool - // The buffer Buf *Buffer - // This is the buffer that was last opened - // This is used to open help, and then go back to the previously opened buffer - lastBuffer *Buffer // The statusline sline Statusline