summaryrefslogtreecommitdiffstats
path: root/pkg/gui/context/merge_conflicts_context.go
blob: 48749373c81c05d9a77bd2358ba2693cc1c9ef0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package context

import (
	"github.com/jesseduffield/gocui"
	"github.com/jesseduffield/lazygit/pkg/gui/mergeconflicts"
	"github.com/jesseduffield/lazygit/pkg/gui/types"
)

type MergeConflictsContext struct {
	types.Context
	viewModel *ConflictsViewModel
	c         *types.HelperCommon
}

type ConflictsViewModel struct {
	state *mergeconflicts.State

	// userVerticalScrolling tells us if the user has started scrolling through the file themselves
	// in which case we won't auto-scroll to a conflict.
	userVerticalScrolling bool
}

func NewMergeConflictsContext(
	view *gocui.View,

	opts ContextCallbackOpts,

	c *types.HelperCommon,
	getOptionsMap func() map[string]string,
) *MergeConflictsContext {
	viewModel := &ConflictsViewModel{
		state:                 mergeconflicts.NewState(),
		userVerticalScrolling: false,
	}

	return &MergeConflictsContext{
		viewModel: viewModel,
		Context: NewSimpleContext(
			NewBaseContext(NewBaseContextOpts{
				Kind:            types.MAIN_CONTEXT,
				View:            view,
				WindowName:      "main",
				Key:             MERGE_CONFLICTS_CONTEXT_KEY,
				OnGetOptionsMap: getOptionsMap,
				Focusable:       true,
			}),
			opts,
		),
		c: c,
	}
}

func (self *MergeConflictsContext) SetUserScrolling(isScrolling bool) {
	self.viewModel.userVerticalScrolling = isScrolling
}

func (self *MergeConflictsContext) IsUserScrolling() bool {
	return self.viewModel.userVerticalScrolling
}

func (self *MergeConflictsContext) State() *mergeconflicts.State {
	return self.viewModel.state
}