From 1ac4a8e7d3584c7d39e4962021bdc19df5ad9ddd Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Fri, 4 Jan 2019 18:08:11 -0500 Subject: [PATCH] Split improvements --- cmd/micro/action/bufhandler.go | 2 ++ cmd/micro/action/tab.go | 32 +++++++++++++++++++++++--- cmd/micro/display/infowindow.go | 7 +++--- cmd/micro/display/window.go | 40 ++++++++++++++++++++------------- cmd/micro/micro.go | 2 +- 5 files changed, 60 insertions(+), 23 deletions(-) diff --git a/cmd/micro/action/bufhandler.go b/cmd/micro/action/bufhandler.go index 11b1884f..2c925fde 100644 --- a/cmd/micro/action/bufhandler.go +++ b/cmd/micro/action/bufhandler.go @@ -219,12 +219,14 @@ func (h *BufHandler) vsplit(buf *buffer.Buffer) { 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) { 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() + MainTab.SetActive(len(MainTab.Panes) - 1) } // BufKeyActions contains the list of all possible key actions the bufhandler could execute diff --git a/cmd/micro/action/tab.go b/cmd/micro/action/tab.go index 4a8c4724..bb9e997f 100644 --- a/cmd/micro/action/tab.go +++ b/cmd/micro/action/tab.go @@ -1,8 +1,6 @@ package action import ( - "log" - "github.com/zyedidia/micro/cmd/micro/views" "github.com/zyedidia/tcell" ) @@ -16,12 +14,40 @@ type TabPane struct { } func (t *TabPane) HandleEvent(event tcell.Event) { + switch e := event.(type) { + case *tcell.EventMouse: + switch e.Buttons() { + case tcell.Button1: + mx, my := e.Position() + + for i, p := range t.Panes { + v := p.GetView() + inpane := mx >= v.X && mx < v.X+v.Width && my >= v.Y && my < v.Y+v.Height + if inpane { + t.active = i + p.SetActive(true) + } else { + p.SetActive(false) + } + } + } + } t.Panes[t.active].HandleEvent(event) } +func (t *TabPane) SetActive(i int) { + t.active = i + for j, p := range t.Panes { + if j == i { + p.SetActive(true) + } else { + p.SetActive(false) + } + } +} + 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 diff --git a/cmd/micro/display/infowindow.go b/cmd/micro/display/infowindow.go index 73f334d2..603c56c3 100644 --- a/cmd/micro/display/infowindow.go +++ b/cmd/micro/display/infowindow.go @@ -81,9 +81,10 @@ func (i *InfoWindow) Resize(w, h int) { // } // } -func (i *InfoWindow) Relocate() bool { return false } -func (i *InfoWindow) GetView() *View { return i.View } -func (i *InfoWindow) SetView(v *View) {} +func (i *InfoWindow) Relocate() bool { return false } +func (i *InfoWindow) GetView() *View { return i.View } +func (i *InfoWindow) SetView(v *View) {} +func (i *InfoWindow) SetActive(b bool) {} func (i *InfoWindow) GetMouseLoc(vloc buffer.Loc) buffer.Loc { c := i.Buffer.GetActiveCursor() diff --git a/cmd/micro/display/window.go b/cmd/micro/display/window.go index 4b0ed338..5bba2153 100644 --- a/cmd/micro/display/window.go +++ b/cmd/micro/display/window.go @@ -1,7 +1,6 @@ package display import ( - "log" "strconv" "unicode/utf8" @@ -31,6 +30,7 @@ type Window interface { SetView(v *View) GetMouseLoc(vloc buffer.Loc) buffer.Loc Resize(w, h int) + SetActive(b bool) } // The BufWindow provides a way of displaying a certain section @@ -41,6 +41,8 @@ type BufWindow struct { // Buffer being shown in this window Buf *buffer.Buffer + active bool + sline *StatusLine lineHeight []int @@ -53,6 +55,7 @@ func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow { w.View = new(View) w.X, w.Y, w.Width, w.Height, w.Buf = x, y, width, height, buf w.lineHeight = make([]int, height) + w.active = true w.sline = NewStatusLine(w) @@ -72,6 +75,10 @@ func (w *BufWindow) Resize(width, height int) { w.lineHeight = make([]int, height) } +func (w *BufWindow) SetActive(b bool) { + w.active = b +} + func (w *BufWindow) getStartInfo(n, lineN int) ([]byte, int, int, *tcell.Style) { tabsize := util.IntOpt(w.Buf.Settings["tabsize"]) width := 0 @@ -226,11 +233,11 @@ func (w *BufWindow) GetMouseLoc(svloc buffer.Loc) buffer.Loc { totalwidth := w.StartCol - nColsBeforeStart - if svloc.X <= vloc.X && vloc.Y == svloc.Y { + if svloc.X <= vloc.X+w.X && vloc.Y+w.Y == svloc.Y { return bloc } for len(line) > 0 { - if vloc.X == svloc.X && vloc.Y == svloc.Y { + if vloc.X+w.X == svloc.X && vloc.Y+w.Y == svloc.Y { return bloc } @@ -249,7 +256,7 @@ func (w *BufWindow) GetMouseLoc(svloc buffer.Loc) buffer.Loc { // Draw any extra characters either spaces for tabs or @ for incomplete wide runes if width > 1 { for i := 1; i < width; i++ { - if vloc.X == svloc.X && vloc.Y == svloc.Y { + if vloc.X+w.X == svloc.X && vloc.Y+w.Y == svloc.Y { return bloc } draw() @@ -276,7 +283,7 @@ func (w *BufWindow) GetMouseLoc(svloc buffer.Loc) buffer.Loc { } } } - if vloc.Y == svloc.Y { + if vloc.Y+w.Y == svloc.Y { return bloc } @@ -287,7 +294,7 @@ func (w *BufWindow) GetMouseLoc(svloc buffer.Loc) buffer.Loc { } } - return buffer.Loc{X: -1, Y: -1} + return buffer.Loc{} } func (w *BufWindow) drawLineNum(lineNumStyle tcell.Style, softwrapped bool, maxLineNumLength int, vloc *buffer.Loc, bloc *buffer.Loc) { @@ -324,11 +331,13 @@ func (w *BufWindow) getStyle(style tcell.Style, bloc buffer.Loc, r rune) (tcell. } func (w *BufWindow) showCursor(x, y int, main bool) { - if main { - screen.Screen.ShowCursor(x, y) - } else { - r, _, _, _ := screen.Screen.GetContent(x, y) - screen.Screen.SetContent(x, y, r, nil, config.DefStyle.Reverse(true)) + if w.active { + if main { + screen.Screen.ShowCursor(x, y) + } else { + r, _, _, _ := screen.Screen.GetContent(x, y) + screen.Screen.SetContent(x, y, r, nil, config.DefStyle.Reverse(true)) + } } } @@ -385,7 +394,7 @@ func (w *BufWindow) displayBuffer() { if b.Settings["ruler"].(bool) { s := lineNumStyle for _, c := range cursors { - if bloc.Y == c.Y { + if bloc.Y == c.Y && w.active { s = curNumStyle break } @@ -415,7 +424,7 @@ func (w *BufWindow) displayBuffer() { } } - if b.Settings["cursorline"].(bool) && + if b.Settings["cursorline"].(bool) && w.active && !c.HasSelection() && c.Y == bloc.Y { if s, ok := config.Colorscheme["cursor-line"]; ok { fg, _, _ := s.Decompose() @@ -438,7 +447,6 @@ func (w *BufWindow) displayBuffer() { nColsBeforeStart-- } - log.Println(len(w.lineHeight), vloc.Y) w.lineHeight[vloc.Y] = bloc.Y totalwidth := w.StartCol - nColsBeforeStart @@ -489,7 +497,7 @@ func (w *BufWindow) displayBuffer() { } for _, c := range cursors { - if b.Settings["cursorline"].(bool) && + if b.Settings["cursorline"].(bool) && w.active && !c.HasSelection() && c.Y == bloc.Y { style := config.DefStyle if s, ok := config.Colorscheme["cursor-line"]; ok { @@ -497,7 +505,7 @@ func (w *BufWindow) displayBuffer() { style = style.Background(fg) } for i := vloc.X; i < w.Width; i++ { - screen.Screen.SetContent(i, vloc.Y, ' ', nil, style) + screen.Screen.SetContent(i+w.X, vloc.Y+w.Y, ' ', nil, style) } } } diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index 8fe6923d..cdece46d 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -223,7 +223,7 @@ func main() { if action.InfoBar.HasPrompt { action.InfoBar.HandleEvent(event) } else { - action.MainTab.Panes[0].HandleEvent(event) + action.MainTab.HandleEvent(event) } } }