Skip to content

Commit

Permalink
Add next/prev conflict keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed Jan 1, 2018
1 parent a3fceef commit fbe44e5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
19 changes: 15 additions & 4 deletions layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,30 @@ func Select(c *conflict.Conflict, g *gocui.Gui, showHelp bool) error {
func Resolve(c *conflict.Conflict, g *gocui.Gui, v *gocui.View, version int) error {
g.Update(func(g *gocui.Gui) error {
c.Choice = version
NextConflict(g, v)
MoveToItem(Down, g, v)
return nil
})
return nil
}

func NextConflict(g *gocui.Gui, v *gocui.View) error {
func MoveToItem(dir int, g *gocui.Gui, v *gocui.View) error {
originalCur := cur

for originalCur != cur {
cur++
for {
if dir == Up {
cur--
} else {
cur++
}

if cur >= conflict.Count {
cur = 0
} else if cur < 0 {
cur = conflict.Count - 1
}

if conflict.All[cur].Choice == 0 || originalCur == cur {
break
}
}

Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func parseInput(g *gocui.Gui, v *gocui.View) error {
Resolve(&conflict.All[cur], g, v, Local)
case in == 'd':
Resolve(&conflict.All[cur], g, v, Incoming)
case in == 'n':
MoveToItem(Down, g, v)
case in == 'p':
MoveToItem(Up, g, v)
case in == 'h' || in == '?':
Select(&conflict.All[cur], g, true)
case in == 'q':
Expand Down
3 changes: 3 additions & 0 deletions summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func printHelp(v *gocui.View) {
j - scroll down
k - scroll up
n - next conflict
p - previous conflict
h | ? - print help
q | Ctrl+c - quit
`
Expand Down

0 comments on commit fbe44e5

Please sign in to comment.