mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-30 06:37:14 +09:00
Fix empty splits and single terms
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
package action
|
||||
|
||||
func (*BufHandler) Suspend() bool {
|
||||
// TODO: error message
|
||||
InfoBar.Error("Suspend is only supported on BSD/Linux")
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user