Skip to content

Commit

Permalink
Fix issues related to cursor and origin when switching ui views
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuathompson committed Dec 22, 2017
1 parent c504c1a commit 5c3aa2b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Table interface {
var currentTable Table
var previousTables []Table
var previousCursors []int
var previousOrigins []int
var chosenItem string

func printNowPlaying() {
Expand Down Expand Up @@ -78,23 +79,30 @@ func pushTable(g *gocui.Gui, v *gocui.View) error {
}

if nt != nil {
previousCursors = append(previousCursors, y)
_, cy := v.Cursor()
_, oy := v.Origin()
previousCursors = append(previousCursors, cy)
previousOrigins = append(previousOrigins, oy)
previousTables = append(previousTables, currentTable)
currentTable = nt
v.SetCursor(0, 0)
v.SetOrigin(0, 0)
}
return nil
}

func popTable(g *gocui.Gui, v *gocui.View) error {
if len(previousTables) > 0 {
lastIndex := previousCursors[len(previousCursors)-1]
lastOrigin := previousOrigins[len(previousOrigins)-1]
currentTable = previousTables[len(previousTables)-1]

previousCursors = previousCursors[:len(previousCursors)-1]
previousOrigins = previousOrigins[:len(previousOrigins)-1]
previousTables = previousTables[:len(previousTables)-1]

err := v.SetCursor(0, lastIndex)
err = v.SetOrigin(0, lastOrigin)

if err != nil {
return err
Expand Down

0 comments on commit 5c3aa2b

Please sign in to comment.