]> git.lizzy.rs Git - micro.git/commitdiff
Replace BufWidth & BufHeight with BufView
authorDmitry Maluka <dmitrymaluka@gmail.com>
Thu, 8 Apr 2021 21:32:00 +0000 (23:32 +0200)
committerDmitry Maluka <dmitrymaluka@gmail.com>
Thu, 8 Apr 2021 21:54:18 +0000 (23:54 +0200)
BufView returns not only the buffer's width and height but also its
x,y position. It may be useful e.g. for checking if a mouse click was
on the actual buffer or ourside it, e.g. on the gutter.

internal/action/actions.go
internal/display/bufwindow.go
internal/display/infowindow.go
internal/display/window.go

index f25ad04e525c8288f8a9f21be9d802ece0745d52..beb63b077dbd9098ed11e5516e6cb62bdd6fc510 100644 (file)
@@ -36,8 +36,8 @@ func (h *BufPane) ScrollDown(n int) {
 func (h *BufPane) ScrollAdjust() {
        v := h.GetView()
        end := h.SLocFromLoc(h.Buf.End())
-       if h.Diff(v.StartLine, end) < h.BufHeight()-1 {
-               v.StartLine = h.Scroll(end, -h.BufHeight()+1)
+       if h.Diff(v.StartLine, end) < h.BufView().Height-1 {
+               v.StartLine = h.Scroll(end, -h.BufView().Height+1)
        }
        h.SetView(v)
 }
@@ -117,7 +117,7 @@ func (h *BufPane) ScrollDownAction() bool {
 // Center centers the view on the cursor
 func (h *BufPane) Center() bool {
        v := h.GetView()
-       v.StartLine = h.Scroll(h.SLocFromLoc(h.Cursor.Loc), -h.BufHeight()/2)
+       v.StartLine = h.Scroll(h.SLocFromLoc(h.Cursor.Loc), -h.BufView().Height/2)
        h.SetView(v)
        h.ScrollAdjust()
        return true
@@ -1290,20 +1290,20 @@ func (h *BufPane) Start() bool {
 // End moves the viewport to the end of the buffer
 func (h *BufPane) End() bool {
        v := h.GetView()
-       v.StartLine = h.Scroll(h.SLocFromLoc(h.Buf.End()), -h.BufHeight()+1)
+       v.StartLine = h.Scroll(h.SLocFromLoc(h.Buf.End()), -h.BufView().Height+1)
        h.SetView(v)
        return true
 }
 
 // PageUp scrolls the view up a page
 func (h *BufPane) PageUp() bool {
-       h.ScrollUp(h.BufHeight())
+       h.ScrollUp(h.BufView().Height)
        return true
 }
 
 // PageDown scrolls the view down a page
 func (h *BufPane) PageDown() bool {
-       h.ScrollDown(h.BufHeight())
+       h.ScrollDown(h.BufView().Height)
        h.ScrollAdjust()
        return true
 }
@@ -1313,7 +1313,7 @@ func (h *BufPane) SelectPageUp() bool {
        if !h.Cursor.HasSelection() {
                h.Cursor.OrigSelection[0] = h.Cursor.Loc
        }
-       h.MoveCursorUp(h.BufHeight())
+       h.MoveCursorUp(h.BufView().Height)
        h.Cursor.SelectTo(h.Cursor.Loc)
        h.Relocate()
        return true
@@ -1324,7 +1324,7 @@ func (h *BufPane) SelectPageDown() bool {
        if !h.Cursor.HasSelection() {
                h.Cursor.OrigSelection[0] = h.Cursor.Loc
        }
-       h.MoveCursorDown(h.BufHeight())
+       h.MoveCursorDown(h.BufView().Height)
        h.Cursor.SelectTo(h.Cursor.Loc)
        h.Relocate()
        return true
@@ -1339,7 +1339,7 @@ func (h *BufPane) CursorPageUp() bool {
                h.Cursor.ResetSelection()
                h.Cursor.StoreVisualX()
        }
-       h.MoveCursorUp(h.BufHeight())
+       h.MoveCursorUp(h.BufView().Height)
        h.Relocate()
        return true
 }
@@ -1353,20 +1353,20 @@ func (h *BufPane) CursorPageDown() bool {
                h.Cursor.ResetSelection()
                h.Cursor.StoreVisualX()
        }
-       h.MoveCursorDown(h.BufHeight())
+       h.MoveCursorDown(h.BufView().Height)
        h.Relocate()
        return true
 }
 
 // HalfPageUp scrolls the view up half a page
 func (h *BufPane) HalfPageUp() bool {
-       h.ScrollUp(h.BufHeight() / 2)
+       h.ScrollUp(h.BufView().Height / 2)
        return true
 }
 
 // HalfPageDown scrolls the view down half a page
 func (h *BufPane) HalfPageDown() bool {
-       h.ScrollDown(h.BufHeight() / 2)
+       h.ScrollDown(h.BufView().Height / 2)
        h.ScrollAdjust()
        return true
 }
index bd8377d68ead65924d35b0ccc9c9411bce97a175..5db6c5fcf43c57943945f8650bdabbe5f7de2aeb 100644 (file)
@@ -94,16 +94,18 @@ func (w *BufWindow) IsActive() bool {
        return w.active
 }
 
-// BufWidth returns the width of the actual buffer displayed in the window,
-// which is usually less than the window width due to the gutter, ruler or scrollbar
-func (w *BufWindow) BufWidth() int {
-       return w.bufWidth
-}
-
-// BufHeight returns the height of the actual buffer displayed in the window,
-// which is usually less than the window height due to the statusline
-func (w *BufWindow) BufHeight() int {
-       return w.bufHeight
+// BufView returns the width, height and x,y location of the actual buffer.
+// It is not exactly the same as the whole window which also contains gutter,
+// ruler, scrollbar and statusline.
+func (w *BufWindow) BufView() View {
+       return View{
+               X:         w.gutterOffset,
+               Y:         0,
+               Width:     w.bufWidth,
+               Height:    w.bufHeight,
+               StartLine: w.StartLine,
+               StartCol:  w.StartCol,
+       }
 }
 
 func (w *BufWindow) updateDisplayInfo() {
index 1892de39addde8eca67e42cc91ace64733077934..7d21facad5452fc96f4cb265a93233c504e2e1c2 100644 (file)
@@ -72,8 +72,16 @@ func (i *InfoWindow) LocFromVisual(vloc buffer.Loc) buffer.Loc {
        return buffer.Loc{c.GetCharPosInLine(l, vloc.X-n), 0}
 }
 
-func (i *InfoWindow) BufWidth() int  { return i.Width }
-func (i *InfoWindow) BufHeight() int { return 1 }
+func (i *InfoWindow) BufView() View {
+       return View{
+               X:         0,
+               Y:         0,
+               Width:     i.Width,
+               Height:    1,
+               StartLine: SLoc{0, 0},
+               StartCol:  0,
+       }
+}
 
 func (i *InfoWindow) Scroll(s SLoc, n int) SLoc        { return s }
 func (i *InfoWindow) Diff(s1, s2 SLoc) int             { return 0 }
index eb2c09f4f628c70c10937271a8678ad369f14790..a321cf4f01ae85ba46c62733f6122edc2528dbbb 100644 (file)
@@ -33,6 +33,5 @@ type BWindow interface {
        Window
        SoftWrap
        SetBuffer(b *buffer.Buffer)
-       BufWidth() int
-       BufHeight() int
+       BufView() View
 }