diff --git a/internal/action/actions.go b/internal/action/actions.go index f25ad04e..beb63b07 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -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 } diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index bd8377d6..5db6c5fc 100644 --- a/internal/display/bufwindow.go +++ b/internal/display/bufwindow.go @@ -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() { diff --git a/internal/display/infowindow.go b/internal/display/infowindow.go index 1892de39..7d21faca 100644 --- a/internal/display/infowindow.go +++ b/internal/display/infowindow.go @@ -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 } diff --git a/internal/display/window.go b/internal/display/window.go index eb2c09f4..a321cf4f 100644 --- a/internal/display/window.go +++ b/internal/display/window.go @@ -33,6 +33,5 @@ type BWindow interface { Window SoftWrap SetBuffer(b *buffer.Buffer) - BufWidth() int - BufHeight() int + BufView() View }