2020-03-29 01:31:34 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2020-11-21 08:15:43 +02:00
|
|
|
"fmt"
|
2020-03-29 01:31:34 +02:00
|
|
|
"strings"
|
|
|
|
|
2021-04-04 15:51:59 +02:00
|
|
|
"github.com/jesseduffield/gocui"
|
2023-07-31 10:32:38 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
2022-01-28 11:44:36 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
2020-03-29 01:31:34 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
|
|
|
)
|
|
|
|
|
2021-11-02 11:35:53 +02:00
|
|
|
const HORIZONTAL_SCROLL_FACTOR = 3
|
|
|
|
|
2022-04-16 07:27:56 +02:00
|
|
|
func (gui *Gui) scrollUpView(view *gocui.View) {
|
|
|
|
view.ScrollUp(gui.c.UserConfig.Gui.ScrollHeight)
|
2020-03-29 01:31:34 +02:00
|
|
|
}
|
|
|
|
|
2022-04-16 07:27:56 +02:00
|
|
|
func (gui *Gui) scrollDownView(view *gocui.View) {
|
|
|
|
scrollHeight := gui.c.UserConfig.Gui.ScrollHeight
|
|
|
|
view.ScrollDown(scrollHeight)
|
2021-04-11 03:43:07 +02:00
|
|
|
|
|
|
|
if manager, ok := gui.viewBufferManagerMap[view.Name()]; ok {
|
|
|
|
manager.ReadLines(scrollHeight)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 05:33:20 +02:00
|
|
|
func (gui *Gui) scrollUpMain() error {
|
2022-06-13 03:01:26 +02:00
|
|
|
var view *gocui.View
|
|
|
|
if gui.c.CurrentContext().GetWindowName() == "secondary" {
|
|
|
|
view = gui.secondaryView()
|
|
|
|
} else {
|
|
|
|
view = gui.mainView()
|
|
|
|
}
|
|
|
|
|
2022-08-06 10:50:52 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.scrollUpView(view)
|
2022-04-16 07:27:56 +02:00
|
|
|
|
|
|
|
return nil
|
2020-03-29 01:31:34 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 05:33:20 +02:00
|
|
|
func (gui *Gui) scrollDownMain() error {
|
2022-06-13 03:01:26 +02:00
|
|
|
var view *gocui.View
|
|
|
|
if gui.c.CurrentContext().GetWindowName() == "secondary" {
|
|
|
|
view = gui.secondaryView()
|
|
|
|
} else {
|
|
|
|
view = gui.mainView()
|
|
|
|
}
|
|
|
|
|
2022-08-06 10:50:52 +02:00
|
|
|
if view.Name() == "mergeConflicts" {
|
|
|
|
gui.State.Contexts.MergeConflicts.SetUserScrolling(true)
|
|
|
|
}
|
|
|
|
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.scrollDownView(view)
|
2022-04-16 07:27:56 +02:00
|
|
|
|
|
|
|
return nil
|
2020-03-29 01:31:34 +02:00
|
|
|
}
|
|
|
|
|
2022-06-13 03:01:26 +02:00
|
|
|
func (gui *Gui) mainView() *gocui.View {
|
2022-12-30 14:24:24 +02:00
|
|
|
viewName := gui.helpers.Window.GetViewNameForWindow("main")
|
2022-06-13 03:01:26 +02:00
|
|
|
view, _ := gui.g.View(viewName)
|
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) secondaryView() *gocui.View {
|
2022-12-30 14:24:24 +02:00
|
|
|
viewName := gui.helpers.Window.GetViewNameForWindow("secondary")
|
2022-06-13 03:01:26 +02:00
|
|
|
view, _ := gui.g.View(viewName)
|
|
|
|
return view
|
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) scrollUpSecondary() error {
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.scrollUpView(gui.secondaryView())
|
2022-04-16 07:27:56 +02:00
|
|
|
|
|
|
|
return nil
|
2020-03-29 01:31:34 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) scrollDownSecondary() error {
|
2022-06-13 03:01:26 +02:00
|
|
|
secondaryView := gui.secondaryView()
|
|
|
|
|
|
|
|
gui.scrollDownView(secondaryView)
|
2022-04-16 07:27:56 +02:00
|
|
|
|
|
|
|
return nil
|
2020-03-29 01:31:34 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) scrollUpConfirmationPanel() error {
|
2021-04-04 15:51:59 +02:00
|
|
|
if gui.Views.Confirmation.Editable {
|
2020-03-29 01:31:34 +02:00
|
|
|
return nil
|
|
|
|
}
|
2021-04-02 10:20:40 +02:00
|
|
|
|
2022-04-16 07:27:56 +02:00
|
|
|
gui.scrollUpView(gui.Views.Confirmation)
|
|
|
|
|
|
|
|
return nil
|
2020-03-29 01:31:34 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) scrollDownConfirmationPanel() error {
|
2021-04-04 15:51:59 +02:00
|
|
|
if gui.Views.Confirmation.Editable {
|
2020-03-29 01:31:34 +02:00
|
|
|
return nil
|
|
|
|
}
|
2021-04-02 10:20:40 +02:00
|
|
|
|
2022-04-16 07:27:56 +02:00
|
|
|
gui.scrollDownView(gui.Views.Confirmation)
|
|
|
|
|
|
|
|
return nil
|
2020-03-29 01:31:34 +02:00
|
|
|
}
|
|
|
|
|
2020-08-22 04:07:03 +02:00
|
|
|
func (gui *Gui) handleCopySelectedSideContextItemToClipboard() error {
|
|
|
|
// important to note that this assumes we've selected an item in a side context
|
2022-12-30 14:24:24 +02:00
|
|
|
currentSideContext := gui.c.CurrentSideContext()
|
|
|
|
if currentSideContext == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
listContext, ok := currentSideContext.(types.IListContext)
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
itemId := listContext.GetSelectedItemId()
|
2020-08-22 04:07:03 +02:00
|
|
|
|
2020-08-22 07:56:30 +02:00
|
|
|
if itemId == "" {
|
2020-08-22 04:07:03 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-16 05:46:53 +02:00
|
|
|
gui.c.LogAction(gui.c.Tr.Actions.CopyToClipboard)
|
2022-02-06 04:42:17 +02:00
|
|
|
if err := gui.os.CopyToClipboard(itemId); err != nil {
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.Error(err)
|
2020-11-21 08:15:43 +02:00
|
|
|
}
|
|
|
|
|
2020-12-24 11:21:54 +02:00
|
|
|
truncatedItemId := utils.TruncateWithEllipsis(strings.Replace(itemId, "\n", " ", -1), 50)
|
2020-11-21 08:15:43 +02:00
|
|
|
|
2023-05-25 13:11:51 +02:00
|
|
|
gui.c.Toast(fmt.Sprintf("'%s' %s", truncatedItemId, gui.c.Tr.CopiedToClipboard))
|
2020-11-21 08:15:43 +02:00
|
|
|
|
|
|
|
return nil
|
2020-08-22 04:07:03 +02:00
|
|
|
}
|
2023-07-31 10:32:38 +02:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|