From bad78797bbe46b348f080a3b3cff451c1c25a40a Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Wed, 12 Feb 2020 13:05:15 -0500 Subject: [PATCH] Clicking tabbar arrow scrolls and fix multicursor Closes #1503 --- internal/action/bufpane.go | 3 +++ internal/action/tab.go | 7 +++++++ internal/buffer/buffer.go | 1 + internal/config/rtfiles.go | 2 -- internal/display/tabwindow.go | 32 ++++++++++++++++---------------- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index 2cbbbab5..9c95c5c7 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -113,6 +113,9 @@ func BufMapKey(k Event, action string) { success := true for i, a := range actionfns { for j, c := range cursors { + if c == nil { + continue + } h.Buf.SetCurCursor(c.Num) h.Cursor = c if i == 0 || (success && types[i-1] == '&') || (!success && types[i-1] == '|') || (types[i-1] == ',') { diff --git a/internal/action/tab.go b/internal/action/tab.go index ac49edb9..d6766655 100644 --- a/internal/action/tab.go +++ b/internal/action/tab.go @@ -104,6 +104,13 @@ func (t *TabList) HandleEvent(event tcell.Event) { mx, my := e.Position() switch e.Buttons() { case tcell.Button1: + if my == t.Y && mx == 0 { + t.Scroll(-4) + return + } else if my == t.Y && mx == t.Width-1 { + t.Scroll(4) + return + } if len(t.List) > 1 { ind := t.LocFromVisual(buffer.Loc{mx, my}) if ind != -1 { diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index e97cf24b..1f761e97 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -763,6 +763,7 @@ func (b *Buffer) ClearCursors() { b.UpdateCursors() b.curCursor = 0 b.GetActiveCursor().ResetSelection() + log.Println("Cleared cursors:", len(b.cursors)) } // MoveLinesUp moves the range of lines up one row diff --git a/internal/config/rtfiles.go b/internal/config/rtfiles.go index 09e91768..1c31cbc1 100644 --- a/internal/config/rtfiles.go +++ b/internal/config/rtfiles.go @@ -199,7 +199,6 @@ func InitRuntimeFiles() { } p.Info, err = NewPluginInfo(data) if err != nil { - log.Println(err) continue } p.Name = p.Info.Name @@ -232,7 +231,6 @@ func InitRuntimeFiles() { } p.Info, err = NewPluginInfo(data) if err != nil { - log.Println(err) continue } p.Name = p.Info.Name diff --git a/internal/display/tabwindow.go b/internal/display/tabwindow.go index 182e675d..0b26fd7b 100644 --- a/internal/display/tabwindow.go +++ b/internal/display/tabwindow.go @@ -14,19 +14,19 @@ type TabWindow struct { Names []string active int Y int - width int + Width int hscroll int } func NewTabWindow(w int, y int) *TabWindow { tw := new(TabWindow) - tw.width = w + tw.Width = w tw.Y = y return tw } func (w *TabWindow) Resize(width, height int) { - w.width = width + w.Width = width } func (w *TabWindow) LocFromVisual(vloc buffer.Loc) int { @@ -40,7 +40,7 @@ func (w *TabWindow) LocFromVisual(vloc buffer.Loc) int { } x += s x += 3 - if x >= w.width { + if x >= w.Width { break } } @@ -50,9 +50,9 @@ func (w *TabWindow) LocFromVisual(vloc buffer.Loc) int { func (w *TabWindow) Scroll(amt int) { w.hscroll += amt s := w.TotalSize() - w.hscroll = util.Clamp(w.hscroll, 0, s-w.width) + w.hscroll = util.Clamp(w.hscroll, 0, s-w.Width) - if s-w.width <= 0 { + if s-w.Width <= 0 { w.hscroll = 0 } } @@ -77,17 +77,17 @@ func (w *TabWindow) SetActive(a int) { for i, n := range w.Names { c := utf8.RuneCountInString(n) if i == a { - if x+c >= w.hscroll+w.width { - w.hscroll = util.Clamp(x+c+1-w.width, 0, s-w.width) + if x+c >= w.hscroll+w.Width { + w.hscroll = util.Clamp(x+c+1-w.Width, 0, s-w.Width) } else if x < w.hscroll { - w.hscroll = util.Clamp(x-4, 0, s-w.width) + w.hscroll = util.Clamp(x-4, 0, s-w.Width) } break } x += c + 4 } - if s-w.width <= 0 { + if s-w.Width <= 0 { w.hscroll = 0 } } @@ -104,13 +104,13 @@ func (w *TabWindow) Display() { if j > 0 { c = ' ' } - if x == w.width-1 && !done { - screen.SetContent(w.width-1, w.Y, '>', nil, config.DefStyle.Reverse(true)) + if x == w.Width-1 && !done { + screen.SetContent(w.Width-1, w.Y, '>', nil, config.DefStyle.Reverse(true)) x++ break } else if x == 0 && w.hscroll > 0 { screen.SetContent(0, w.Y, '<', nil, config.DefStyle.Reverse(true)) - } else if x >= 0 && x < w.width { + } else if x >= 0 && x < w.Width { screen.SetContent(x, w.Y, c, nil, config.DefStyle.Reverse(true)) } x++ @@ -136,12 +136,12 @@ func (w *TabWindow) Display() { } else { draw(' ', 3) } - if x >= w.width { + if x >= w.Width { break } } - if x < w.width { - draw(' ', w.width-x) + if x < w.Width { + draw(' ', w.Width-x) } }