summaryrefslogtreecommitdiffstats
path: root/pkg/gui/gui.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-10-30 20:23:25 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-11-05 19:22:01 +1100
commit820f3d5cbb556f1c117906e4174f35ecf71e2ed5 (patch)
tree591c593fff6636707d06860cc7b918a92c573de0 /pkg/gui/gui.go
parent081598d98944cdb95bfa649812565127c0592f5e (diff)
support split view in staging panel and staging ranges
Diffstat (limited to 'pkg/gui/gui.go')
-rw-r--r--pkg/gui/gui.go47
1 files changed, 41 insertions, 6 deletions
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 21dde6dd9..f499895a1 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -23,6 +23,7 @@ import (
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands"
"github.com/jesseduffield/lazygit/pkg/config"
+ "github.com/jesseduffield/lazygit/pkg/git"
"github.com/jesseduffield/lazygit/pkg/i18n"
"github.com/jesseduffield/lazygit/pkg/theme"
"github.com/jesseduffield/lazygit/pkg/updates"
@@ -83,10 +84,13 @@ type Gui struct {
// non-mutative, so that we don't accidentally end up
// with mismatches of data. We might change this in the future
type stagingPanelState struct {
- SelectedLine int
- StageableLines []int
- HunkStarts []int
- Diff string
+ SelectedLineIdx int
+ FirstLineIdx int
+ LastLineIdx int
+ Diff string
+ PatchParser *git.PatchParser
+ SelectMode int // one of LINE, HUNK, or RANGE
+ IndexFocused bool // this is for if we show the left or right panel
}
type mergingPanelState struct {
@@ -147,6 +151,7 @@ type guiState struct {
WorkingTreeState string // one of "merging", "rebasing", "normal"
Contexts map[string]string
CherryPickedCommits []*commands.Commit
+ SplitMainPanel bool
}
// NewGui builds a new gui handler
@@ -258,6 +263,7 @@ func (gui *Gui) onFocusLost(v *gocui.View, newView *gocui.View) error {
if v == nil {
return nil
}
+ gui.State.SplitMainPanel = false
if v.Name() == "branches" {
// This stops the branches panel from showing the upstream/downstream changes to the selected branch, when it loses focus
// inside renderListPanel it checks to see if the panel has focus
@@ -359,7 +365,6 @@ func (gui *Gui) layout(g *gocui.Gui) error {
}
optionsVersionBoundary := width - max(len(utils.Decolorise(information)), 1)
- leftSideWidth := width / 3
appStatus := gui.statusManager.getStatusString()
appStatusOptionsBoundary := 0
@@ -376,7 +381,23 @@ func (gui *Gui) layout(g *gocui.Gui) error {
g.DeleteView("limit")
textColor := theme.GocuiDefaultTextColor
- v, err := g.SetView("main", leftSideWidth+panelSpacing, 0, width-1, height-2, gocui.LEFT)
+ leftSideWidth := width / 3
+ panelSplitX := width - 1
+ if gui.State.SplitMainPanel {
+ units := 7
+ leftSideWidth = width / units
+ panelSplitX = (1 + ((units - 1) / 2)) * width / units
+ }
+
+ main := "main"
+ secondary := "secondary"
+ swappingMainPanels := gui.State.Panels.Staging != nil && gui.State.Panels.Staging.IndexFocused
+ if swappingMainPanels {
+ main = "secondary"
+ secondary = "main"
+ }
+
+ v, err := g.SetView(main, leftSideWidth+panelSpacing, 0, panelSplitX, height-2, gocui.LEFT)
if err != nil {
if err.Error() != "unknown view" {
return err
@@ -386,6 +407,20 @@ func (gui *Gui) layout(g *gocui.Gui) error {
v.FgColor = textColor
}
+ hiddenViewOffset := 0
+ if !gui.State.SplitMainPanel {
+ hiddenViewOffset = 9999
+ }
+ secondaryView, err := g.SetView(secondary, panelSplitX+1+hiddenViewOffset, hiddenViewOffset, width-1+hiddenViewOffset, height-2+hiddenViewOffset, gocui.LEFT)
+ if err != nil {
+ if err.Error() != "unknown view" {
+ return err
+ }
+ secondaryView.Title = gui.Tr.SLocalize("DiffTitle")
+ secondaryView.Wrap = true
+ secondaryView.FgColor = gocui.ColorWhite
+ }
+
if v, err := g.SetView("status", 0, 0, leftSideWidth, vHeights["status"]-1, gocui.BOTTOM|gocui.RIGHT); err != nil {
if err.Error() != "unknown view" {
return err