summaryrefslogtreecommitdiffstats
path: root/pkg/gui/stash_panel.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-03-23 11:42:19 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-03-23 11:54:25 +1100
commitd84dfc23e7fe4e70ffd129a769d641c917972738 (patch)
tree91993749fd23b972b0aee1a101f3c2830de76295 /pkg/gui/stash_panel.go
parent9d8fd3594eac927504de2be3ff8dbf32cf6b84b6 (diff)
Rely on model rather than view to focus a point
Currently when we want to focus a point on a view (i.e. highlight a line and ensure it's within the bounds of a view's box, we use the LinesHeight method on the view to work out how many lines in total there are. This is bad because for example if we come back from editing a file, the view will have no contents so LinesHeight == 0, but we might be trying to select line 10 because there are actual ten things we expect to be rendered already. This causes a crash when e.g. 10 is greater than the height of the view. So we need to pass in to our FocusPoint method the actual number of items we want to render, rather than having the method rely on the LinesHeight, so that the method knows to scroll a bit before setting the cursor's y position. Unfortunately this makes for some awkward code with our current setup. We don't have a good interface type on these state objects so we now need to explicitly obtain the len() of whatever array we're rendering. In the case of the menu panel this is even more awkward because the items list is just an interface{} and it's not easy to get the list of that, so now when we instantiate a menu we need to pass in the count of items as well. The better solution would be to define an interface with a getItems and getLength method and have all these item arrays become structs implementing the interface, but I am too lazy to do this right now :)
Diffstat (limited to 'pkg/gui/stash_panel.go')
-rw-r--r--pkg/gui/stash_panel.go2
1 files changed, 1 insertions, 1 deletions
diff --git a/pkg/gui/stash_panel.go b/pkg/gui/stash_panel.go
index 05844f0ac..9c1851971 100644
--- a/pkg/gui/stash_panel.go
+++ b/pkg/gui/stash_panel.go
@@ -31,7 +31,7 @@ func (gui *Gui) handleStashEntrySelect(g *gocui.Gui, v *gocui.View) error {
if stashEntry == nil {
return gui.renderString(g, "main", gui.Tr.SLocalize("NoStashEntries"))
}
- if err := gui.focusPoint(0, gui.State.Panels.Stash.SelectedLine, v); err != nil {
+ if err := gui.focusPoint(0, gui.State.Panels.Stash.SelectedLine, len(gui.State.StashEntries), v); err != nil {
return err
}
go func() {