summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context/viewport_list_context_trait.go
blob: b89dea83239fc93a5dd042d860174ab32e6ecfb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package context

import (
	"github.com/jesseduffield/lazygit/pkg/utils"
)

// This embeds a list context trait and adds logic to re-render the viewport
// whenever a line is focused. We use this in the commits panel because different
// sections of the log graph need to be highlighted depending on the currently selected line

type ViewportListContextTrait struct {
	*ListContextTrait
}

func (self *ViewportListContextTrait) FocusLine() {
	self.ListContextTrait.FocusLine()

	startIdx, length := self.GetViewTrait().ViewPortYBounds()
	displayStrings := self.ListContextTrait.getDisplayStrings(startIdx, length)
	content := utils.RenderDisplayStrings(displayStrings)
	self.GetViewTrait().SetViewPortContent(content)
}