]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/tab.go
Go plugin should disable tabstospaces if the file is go
[micro.git] / cmd / micro / tab.go
index cada1b726c1672cf5f326ba7ee3e2edbdf2cd0b6..9109eb9fb1dba988027f6aeba90669a0b1119593 100644 (file)
@@ -15,31 +15,57 @@ type Tab struct {
        curView int
        // Generally this is the name of the current view's buffer
        name string
+
+       tree *SplitTree
 }
 
+// NewTabFromView creates a new tab and puts the given view in the tab
 func NewTabFromView(v *View) *Tab {
        t := new(Tab)
        t.views = append(t.views, v)
        t.views[0].Num = 0
+
+       t.tree = new(SplitTree)
+       t.tree.kind = VerticalSplit
+       t.tree.children = []Node{NewLeafNode(t.views[0], t.tree)}
+
+       w, h := screen.Size()
+       t.tree.width = w
+       t.tree.height = h - 1
        return t
 }
 
+// SetNum sets all this tab's views to have the correct tab number
 func (t *Tab) SetNum(num int) {
        for _, v := range t.views {
                v.TabNum = num
        }
 }
 
+func (t *Tab) Cleanup() {
+       t.tree.Cleanup()
+}
+
+func (t *Tab) Resize() {
+       w, h := screen.Size()
+       t.tree.width = w
+       t.tree.height = h - 1
+       t.tree.ResizeSplits()
+}
+
 // CurView returns the current view
 func CurView() *View {
        curTab := tabs[curTab]
        return curTab.views[curTab.curView]
 }
 
+// TabbarString returns the string that should be displayed in the tabbar
+// It also returns a map containing which indicies correspond to which tab number
+// This is useful when we know that the mouse click has occured at an x location
+// but need to know which tab that corresponds to to accurately change the tab
 func TabbarString() (string, map[int]int) {
        str := ""
        indicies := make(map[int]int)
-       indicies[0] = 0
        for i, t := range tabs {
                if i == curTab {
                        str += "["
@@ -58,7 +84,11 @@ func TabbarString() (string, map[int]int) {
        return str, indicies
 }
 
+// TabbarHandleMouseEvent checks the given mouse event if it is clicking on the tabbar
+// If it is it changes the current tab accordingly
+// This function returns true if the tab is changed
 func TabbarHandleMouseEvent(event tcell.Event) bool {
+       // There is no tabbar displayed if there are less than 2 tabs
        if len(tabs) <= 1 {
                return false
        }
@@ -66,6 +96,7 @@ func TabbarHandleMouseEvent(event tcell.Event) bool {
        switch e := event.(type) {
        case *tcell.EventMouse:
                button := e.Buttons()
+               // Must be a left click
                if button == tcell.Button1 {
                        x, y := e.Position()
                        if y != 0 {
@@ -95,6 +126,7 @@ func TabbarHandleMouseEvent(event tcell.Event) bool {
        return false
 }
 
+// DisplayTabs displays the tabbar at the top of the editor if there are multiple tabs
 func DisplayTabs() {
        if len(tabs) <= 1 {
                return