From 8f0023785710631de5eea75b83802aa707a0a051 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sun, 13 Jan 2019 18:18:23 -0500 Subject: [PATCH] Fix empty splits and single terms --- cmd/micro/action/actions.go | 12 ++++++------ cmd/micro/action/actions_other.go | 2 +- cmd/micro/action/bufhandler.go | 8 ++++---- cmd/micro/action/command.go | 31 +++++++++++++++++++++++++++---- cmd/micro/display/statusline.go | 7 +++---- cmd/micro/shell/terminal.go | 2 -- 6 files changed, 41 insertions(+), 21 deletions(-) diff --git a/cmd/micro/action/actions.go b/cmd/micro/action/actions.go index 4179af32..d280c333 100644 --- a/cmd/micro/action/actions.go +++ b/cmd/micro/action/actions.go @@ -1065,16 +1065,16 @@ func (h *BufHandler) NextTab() bool { return false } -// VSplitBinding opens an empty vertical split -func (h *BufHandler) VSplitBinding() bool { - h.vsplit(buffer.NewBufferFromString("", "", buffer.BTDefault)) +// VSplitAction opens an empty vertical split +func (h *BufHandler) VSplitAction() bool { + h.VSplitBuf(buffer.NewBufferFromString("", "", buffer.BTDefault)) return false } -// HSplitBinding opens an empty horizontal split -func (h *BufHandler) HSplitBinding() bool { - h.hsplit(buffer.NewBufferFromString("", "", buffer.BTDefault)) +// HSplitAction opens an empty horizontal split +func (h *BufHandler) HSplitAction() bool { + h.HSplitBuf(buffer.NewBufferFromString("", "", buffer.BTDefault)) return false } diff --git a/cmd/micro/action/actions_other.go b/cmd/micro/action/actions_other.go index 15699895..52e94376 100644 --- a/cmd/micro/action/actions_other.go +++ b/cmd/micro/action/actions_other.go @@ -3,6 +3,6 @@ package action func (*BufHandler) Suspend() bool { - // TODO: error message + InfoBar.Error("Suspend is only supported on BSD/Linux") return false } diff --git a/cmd/micro/action/bufhandler.go b/cmd/micro/action/bufhandler.go index 571748d3..0ffa514f 100644 --- a/cmd/micro/action/bufhandler.go +++ b/cmd/micro/action/bufhandler.go @@ -254,14 +254,14 @@ func (h *BufHandler) DoRuneInsert(r rune) { } } -func (h *BufHandler) vsplit(buf *buffer.Buffer) { +func (h *BufHandler) VSplitBuf(buf *buffer.Buffer) { e := NewBufEditPane(0, 0, 0, 0, buf) e.splitID = MainTab().GetNode(h.splitID).VSplit(h.Buf.Settings["splitright"].(bool)) MainTab().Panes = append(MainTab().Panes, e) MainTab().Resize() MainTab().SetActive(len(MainTab().Panes) - 1) } -func (h *BufHandler) hsplit(buf *buffer.Buffer) { +func (h *BufHandler) HSplitBuf(buf *buffer.Buffer) { e := NewBufEditPane(0, 0, 0, 0, buf) e.splitID = MainTab().GetNode(h.splitID).HSplit(h.Buf.Settings["splitbottom"].(bool)) MainTab().Panes = append(MainTab().Panes, e) @@ -350,8 +350,8 @@ var BufKeyActions = map[string]BufKeyAction{ "NextSplit": (*BufHandler).NextSplit, "PreviousSplit": (*BufHandler).PreviousSplit, "Unsplit": (*BufHandler).Unsplit, - "VSplit": (*BufHandler).VSplitBinding, - "HSplit": (*BufHandler).HSplitBinding, + "VSplit": (*BufHandler).VSplitAction, + "HSplit": (*BufHandler).HSplitAction, "ToggleMacro": (*BufHandler).ToggleMacro, "PlayMacro": (*BufHandler).PlayMacro, "Suspend": (*BufHandler).Suspend, diff --git a/cmd/micro/action/command.go b/cmd/micro/action/command.go index 8ae80064..814c99cb 100644 --- a/cmd/micro/action/command.go +++ b/cmd/micro/action/command.go @@ -198,25 +198,37 @@ func (h *BufHandler) HelpCmd(args []string) { // VSplitCmd opens a vertical split with file given in the first argument // If no file is given, it opens an empty buffer in a new split func (h *BufHandler) VSplitCmd(args []string) { + if len(args) == 0 { + // Open an empty vertical split + h.VSplitAction() + return + } + buf, err := buffer.NewBufferFromFile(args[0], buffer.BTDefault) if err != nil { InfoBar.Error(err) return } - h.vsplit(buf) + h.VSplitBuf(buf) } // HSplitCmd opens a horizontal split with file given in the first argument // If no file is given, it opens an empty buffer in a new split func (h *BufHandler) HSplitCmd(args []string) { + if len(args) == 0 { + // Open an empty horizontal split + h.HSplitAction() + return + } + buf, err := buffer.NewBufferFromFile(args[0], buffer.BTDefault) if err != nil { InfoBar.Error(err) return } - h.hsplit(buf) + h.HSplitBuf(buf) } // EvalCmd evaluates a lua expression @@ -318,10 +330,21 @@ func (h *BufHandler) TermCmd(args []string) { } term := func(i int) { - v := h.GetView() + // If there is only one open file we make a new tab instead of overwriting it + newtab := len(MainTab().Panes) == 1 && len(Tabs.List) == 1 + t := new(shell.Terminal) t.Start(args, false, true) - MainTab().Panes[i] = NewTermHandler(v.X, v.Y, v.Width, v.Height, t, h.ID()) + + id := h.ID() + if newtab { + h.AddTab() + i = 0 + id = MainTab().Panes[0].ID() + } + + v := h.GetView() + MainTab().Panes[i] = NewTermHandler(v.X, v.Y, v.Width, v.Height, t, id) MainTab().SetActive(i) } diff --git a/cmd/micro/display/statusline.go b/cmd/micro/display/statusline.go index e6b06033..c1e72a41 100644 --- a/cmd/micro/display/statusline.go +++ b/cmd/micro/display/statusline.go @@ -70,9 +70,9 @@ var formatParser = regexp.MustCompile(`\$\(.+?\)`) // Display draws the statusline to the screen func (s *StatusLine) Display() { // TODO: don't display if infobar off and has message - // if !GetGlobalOption("infobar").(bool) { - // return - // } + if !config.GetGlobalOption("infobar").(bool) { + return + } // We'll draw the line at the lowest line in the window y := s.win.Height + s.win.Y - 1 @@ -84,7 +84,6 @@ func (s *StatusLine) Display() { return []byte(fmt.Sprint(s.FindOpt(string(option)))) } else if bytes.HasPrefix(name, []byte("bind")) { binding := string(name[5:]) - // TODO: search bindings for k, v := range config.Bindings { if v == binding { return []byte(k) diff --git a/cmd/micro/shell/terminal.go b/cmd/micro/shell/terminal.go index ea098221..bfb7fa87 100644 --- a/cmd/micro/shell/terminal.go +++ b/cmd/micro/shell/terminal.go @@ -94,8 +94,6 @@ func (t *Terminal) Start(execCmd []string, getOutput bool, wait bool) error { screen.Redraw() } t.Stop() - // TODO: close Term - // closeterm <- view.Num }() return nil