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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
package gui
import (
"fmt"
"strings"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)
const HORIZONTAL_SCROLL_FACTOR = 3
func (gui *Gui) scrollUpView(view *gocui.View) {
view.ScrollUp(gui.c.UserConfig.Gui.ScrollHeight)
}
func (gui *Gui) scrollDownView(view *gocui.View) {
scrollHeight := gui.c.UserConfig.Gui.ScrollHeight
view.ScrollDown(scrollHeight)
if manager, ok := gui.viewBufferManagerMap[view.Name()]; ok {
manager.ReadLines(scrollHeight)
}
}
func (gui *Gui) scrollUpMain() error {
var view *gocui.View
if gui.c.CurrentContext().GetWindowName() == "secondary" {
view = gui.secondaryView()
} else {
view = gui.mainView()
}
if view.Name() == "mergeConflicts" {
// although we have this same logic in the controller, this method can be invoked
// via the global scroll up/down keybindings, as opposed to just the mouse wheel keybinding.
// It would be nice to have a concept of a global keybinding that runs on the top context in a
// window but that might be overkill for this one use case.
gui.State.Contexts.MergeConflicts.SetUserScrolling(true)
}
gui.scrollUpView(view)
return nil
}
func (gui *Gui) scrollDownMain() error {
var view *gocui.View
if gui.c.CurrentContext().GetWindowName() == "secondary" {
view = gui.secondaryView()
} else {
view = gui.mainView()
}
if view.Name() == "mergeConflicts" {
gui.State.Contexts.MergeConflicts.SetUserScrolling(true)
}
gui.scrollDownView(view)
return nil
}
func (gui *Gui) mainView() *gocui.View {
viewName := gui.helpers.Window.GetViewNameForWindow("main")
view, _ := gui.g.View(viewName)
return view
}
func (gui *Gui) secondaryView() *gocui.View {
viewName := gui.helpers.Window.GetViewNameForWindow("secondary")
view, _ := gui.g.View(viewName)
return view
}
func (gui *Gui) scrollUpSecondary() error {
gui.scrollUpView(gui.secondaryView())
return nil
}
func (gui *Gui) scrollDownSecondary() error {
secondaryView := gui.secondaryView()
gui.scrollDownView(secondaryView)
return nil
}
func (gui *Gui) scrollUpConfirmationPanel() error {
if gui.Views.Confirmation.Editable {
return nil
}
gui.scrollUpView(gui.Views.Confirmation)
return nil
}
func (gui *Gui) scrollDownConfirmationPanel() error {
if gui.Views.Confirmation.Editable {
return nil
}
gui.scrollDownView(gui.Views.Confirmation)
return nil
}
func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error {
// important to note that this assumes we've selected an item in a side context
currentSideContext := gui.c.CurrentSideContext()
if currentSideContext == nil {
return nil
}
listContext, ok := currentSideContext.(types.IListContext)
if !ok {
return nil
}
itemId := listContext.GetSelectedItemId()
if itemId == "" {
return nil
}
gui.c.LogAction(gui.c.Tr.Actions.CopyToClipboard)
if err := gui.os.CopyToClipboard(itemId); err != nil {
return gui.c.Error(err)
}
truncatedItemId := utils.TruncateWithEllipsis(strings.Replace(itemId, "\n", " ", -1), 50)
gui.c.Toast(fmt.Sprintf("'%s' %s", truncatedItemId, gui.c.Tr.CopiedToClipboard))
return nil
}
func (gui *Gui) getCopySelectedSideContextItemToClipboardDisabledReason() *types.DisabledReason {
// important to note that this assumes we've selected an item in a side context
currentSideContext := gui.c.CurrentSideContext()
if currentSideContext == nil {
// This should never happen but if it does we'll just ignore the keypress
return nil
}
listContext, ok := currentSideContext.(types.IListContext)
if !ok {
// This should never happen but if it does we'll just ignore the keypress
return nil
}
startIdx, endIdx := listContext.GetList().GetSelectionRange()
if startIdx != endIdx {
return &types.DisabledReason{Text: gui.Tr.RangeSelectNotSupported}
}
return nil
}
func (gui *Gui) setCaption(caption string) {
gui.Views.Options.FgColor = gocui.ColorWhite
gui.Views.Options.FgColor |= gocui.AttrBold
gui.Views.Options.SetContent(captionPrefix + " " + style.FgCyan.SetBold().Sprint(caption))
gui.c.Render()
}
var captionPrefix = ""
func (gui *Gui) setCaptionPrefix(prefix string) {
gui.Views.Options.FgColor = gocui.ColorWhite
gui.Views.Options.FgColor |= gocui.AttrBold
captionPrefix = prefix
gui.Views.Options.SetContent(prefix)
gui.c.Render()
}
|