Start working on splits

This commit is contained in:
Zachary Yedidia
2019-01-04 17:40:56 -05:00
parent d4c410f3dc
commit 541daf212e
9 changed files with 465 additions and 3 deletions

View File

@@ -90,6 +90,8 @@ type BufHandler struct {
// Last search stores the last successful search for FindNext and FindPrev
lastSearch string
splitID uint64
}
func NewBufHandler(buf *buffer.Buffer, win display.Window) *BufHandler {
@@ -212,6 +214,19 @@ func (h *BufHandler) DoRuneInsert(r rune) {
}
}
func (h *BufHandler) vsplit(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()
}
func (h *BufHandler) hsplit(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)
MainTab.Resize()
}
// BufKeyActions contains the list of all possible key actions the bufhandler could execute
var BufKeyActions = map[string]BufKeyAction{
"CursorUp": (*BufHandler).CursorUp,

View File

@@ -3,6 +3,7 @@ package action
import (
"os"
"github.com/zyedidia/micro/cmd/micro/buffer"
"github.com/zyedidia/micro/cmd/micro/shellwords"
"github.com/zyedidia/micro/cmd/micro/util"
)
@@ -198,11 +199,25 @@ func Help(args []string) {
// VSplit 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 VSplit(args []string) {
buf, err := buffer.NewBufferFromFile(args[0], buffer.BTDefault)
if err != nil {
InfoBar.Error(err)
return
}
MainTab.CurPane().vsplit(buf)
}
// HSplit 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 HSplit(args []string) {
buf, err := buffer.NewBufferFromFile(args[0], buffer.BTDefault)
if err != nil {
InfoBar.Error(err)
return
}
MainTab.CurPane().hsplit(buf)
}
// Eval evaluates a lua expression

View File

@@ -4,6 +4,7 @@ import (
"github.com/zyedidia/micro/cmd/micro/buffer"
"github.com/zyedidia/micro/cmd/micro/display"
"github.com/zyedidia/micro/cmd/micro/info"
"github.com/zyedidia/micro/cmd/micro/views"
)
type EditPane struct {
@@ -27,6 +28,17 @@ func NewBufEditPane(x, y, width, height int, b *buffer.Buffer) *EditPane {
return e
}
func NewTabPane(width, height int, b *buffer.Buffer) *TabPane {
t := new(TabPane)
t.Node = views.NewRoot(0, 0, width, height)
e := NewBufEditPane(0, 0, width, height, b)
e.splitID = t.ID()
t.Panes = append(t.Panes, e)
return t
}
func NewInfoBar() *InfoPane {
e := new(InfoPane)
ib := info.NewBuffer()

35
cmd/micro/action/tab.go Normal file
View File

@@ -0,0 +1,35 @@
package action
import (
"log"
"github.com/zyedidia/micro/cmd/micro/views"
"github.com/zyedidia/tcell"
)
var MainTab *TabPane
type TabPane struct {
*views.Node
Panes []*EditPane
active int
}
func (t *TabPane) HandleEvent(event tcell.Event) {
t.Panes[t.active].HandleEvent(event)
}
func (t *TabPane) Resize() {
for _, p := range t.Panes {
log.Println(p.splitID)
v := t.GetNode(p.splitID).GetView()
pv := p.GetView()
pv.X, pv.Y = v.X, v.Y
p.SetView(pv)
p.Resize(v.W, v.H)
}
}
func (t *TabPane) CurPane() *EditPane {
return t.Panes[t.active]
}