summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-04-16 15:27:56 +1000
committerJesse Duffield <jessedduffield@gmail.com>2022-04-16 17:29:17 +1000
commite68093fe9974296fe5afb22ec8e0adb1eb2f4316 (patch)
tree040dbfdb4dc438271d9f3febae410d25698f1a38 /pkg/gui/context
parentb838b74801102b27782cc20c7396279630e77fba (diff)
add scrollbars
Diffstat (limited to 'pkg/gui/context')
-rw-r--r--pkg/gui/context/view_trait.go26
-rw-r--r--pkg/gui/context/viewport_list_context_trait.go4
2 files changed, 20 insertions, 10 deletions
diff --git a/pkg/gui/context/view_trait.go b/pkg/gui/context/view_trait.go
index 4c0cd9e05..8f2a2e99e 100644
--- a/pkg/gui/context/view_trait.go
+++ b/pkg/gui/context/view_trait.go
@@ -3,7 +3,6 @@ package context
import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/types"
- "github.com/jesseduffield/lazygit/pkg/utils"
)
const HORIZONTAL_SCROLL_FACTOR = 3
@@ -43,20 +42,31 @@ func (self *ViewTrait) SetOriginX(value int) {
_ = self.view.SetOriginX(value)
}
-// tells us the bounds of line indexes shown in the view currently
+// tells us the start of line indexes shown in the view currently as well as the capacity of lines shown in the viewport.
func (self *ViewTrait) ViewPortYBounds() (int, int) {
- _, min := self.view.Origin()
- max := self.view.InnerHeight() + 1
- return min, max
+ _, start := self.view.Origin()
+ length := self.view.InnerHeight() + 1
+ return start, length
}
func (self *ViewTrait) ScrollLeft() {
- newOriginX := utils.Max(self.view.OriginX()-self.view.InnerWidth()/HORIZONTAL_SCROLL_FACTOR, 0)
- _ = self.view.SetOriginX(newOriginX)
+ self.view.ScrollLeft(self.horizontalScrollAmount())
}
func (self *ViewTrait) ScrollRight() {
- _ = self.view.SetOriginX(self.view.OriginX() + self.view.InnerWidth()/HORIZONTAL_SCROLL_FACTOR)
+ self.view.ScrollRight(self.horizontalScrollAmount())
+}
+
+func (self *ViewTrait) horizontalScrollAmount() int {
+ return self.view.InnerWidth() / HORIZONTAL_SCROLL_FACTOR
+}
+
+func (self *ViewTrait) ScrollUp() {
+ self.view.ScrollUp(1)
+}
+
+func (self *ViewTrait) ScrollDown() {
+ self.view.ScrollDown(1)
}
// this returns the amount we'll scroll if we want to scroll by a page.
diff --git a/pkg/gui/context/viewport_list_context_trait.go b/pkg/gui/context/viewport_list_context_trait.go
index ab9b04fb8..b89dea832 100644
--- a/pkg/gui/context/viewport_list_context_trait.go
+++ b/pkg/gui/context/viewport_list_context_trait.go
@@ -15,8 +15,8 @@ type ViewportListContextTrait struct {
func (self *ViewportListContextTrait) FocusLine() {
self.ListContextTrait.FocusLine()
- min, max := self.GetViewTrait().ViewPortYBounds()
- displayStrings := self.ListContextTrait.getDisplayStrings(min, max)
+ startIdx, length := self.GetViewTrait().ViewPortYBounds()
+ displayStrings := self.ListContextTrait.getDisplayStrings(startIdx, length)
content := utils.RenderDisplayStrings(displayStrings)
self.GetViewTrait().SetViewPortContent(content)
}