Skip to content

Commit

Permalink
Add up and down scrolling to panel views
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Dec 30, 2017
1 parent e3e9f54 commit 1e38e63
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
30 changes: 30 additions & 0 deletions conflict.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ func (c *Conflict) Select(g *gocui.Gui, withHelp bool) error {
buf.WriteString(" (Current Change) ")
v.Title = buf.String()

top, bottom := c.getPaddingLines()
v.Clear()
printLines(v, top)
printLines(v, c.ColoredCurrentLines)
printLines(v, bottom)

v, err = g.View(Foreign)
if err != nil {
Expand All @@ -87,7 +91,11 @@ func (c *Conflict) Select(g *gocui.Gui, withHelp bool) error {
buf.WriteString(" (Incoming Change) ")
v.Title = buf.String()

top, bottom = c.getPaddingLines()
v.Clear()
printLines(v, top)
printLines(v, c.ColoredForeignLines)
printLines(v, bottom)
return nil
})
return nil
Expand All @@ -102,6 +110,28 @@ func (c *Conflict) Resolve(g *gocui.Gui, v *gocui.View, version int) error {
return nil
}

func (c *Conflict) getPaddingLines() (topPadding, bottomPadding []string) {
lines := allFileLines[c.AbsolutePath]
start, end := c.Start-1, c.End

if c.topPeek >= start {
c.topPeek = start
}

for _, l := range lines[start-c.topPeek : start] {
topPadding = append(topPadding, Colorize(l, Gray))
}

if c.bottomPeek >= len(lines)-c.End {
c.bottomPeek = len(lines) - c.End
}

for _, l := range lines[end : end+c.bottomPeek] {
bottomPadding = append(bottomPadding, Colorize(l, Gray))
}
return
}

func nextConflict(g *gocui.Gui, v *gocui.View) error {
originalCur := cur

Expand Down
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ func parseInput(g *gocui.Gui, v *gocui.View) error {
v.SetCursor(0, 0)

switch {
case in == "w":
conflicts[cur].topPeek++
conflicts[cur].Select(g, false)
case in == "s":
conflicts[cur].bottomPeek++
conflicts[cur].Select(g, false)
case in == "a":
conflicts[cur].Resolve(g, v, Local)
case in == "d":
Expand Down

0 comments on commit 1e38e63

Please sign in to comment.