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)
}
// 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
// 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
}
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
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
h.Cursor.ResetSelection()
h.Cursor.StoreVisualX()
}
- h.MoveCursorUp(h.BufHeight())
+ h.MoveCursorUp(h.BufView().Height)
h.Relocate()
return true
}
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
}
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() {