Fix empty splits and single terms

This commit is contained in:
Zachary Yedidia
2019-01-13 18:18:23 -05:00
parent 3fc769e54a
commit 8f00237857
6 changed files with 41 additions and 21 deletions

View File

@@ -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
}

View File

@@ -3,6 +3,6 @@
package action
func (*BufHandler) Suspend() bool {
// TODO: error message
InfoBar.Error("Suspend is only supported on BSD/Linux")
return false
}

View File

@@ -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,

View File

@@ -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)
}

View File

@@ -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)

View File

@@ -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