Skip to content

Commit

Permalink
fix: always try to put cursor on first module
Browse files Browse the repository at this point in the history
  • Loading branch information
leg100 committed Dec 29, 2024
1 parent 17dba76 commit 45bc7a6
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions internal/tui/explorer/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,32 @@ func (t *tracker) reindex(tree *tree, height int) {
t.doReindex(tree)
t.selector.reindex(t.nodes)

// When pug first starts up, for the user's convenience we want the cursor
// to be on the first module. Because modules are added asynchronously, a
// semaphore detects whether the cursor has been set to the first module, to
// ensure this is only done once.
if !t.initialized {
placeCursorOnFirstModule := func() bool {
for i, n := range t.nodes {
if _, ok := n.(moduleNode); ok {
t.cursorNode = t.nodes[i]
t.cursorIndex = i
t.initialized = true
break
return true
}
}
// If no modules found then set cursor on first node
if t.cursorIndex < 0 {
t.cursorNode = t.nodes[0]
t.cursorIndex = 0
}
return false
}
if t.cursorIndex < 0 {
t.cursorNode = t.nodes[0]
t.cursorIndex = 0

// When pug first starts up, for the user's convenience we want the cursor
// to be on the first module. Because modules are added asynchronously, a
// semaphore detects whether the cursor has been set to the first module, to
// ensure this is only done once.
if !t.initialized {
if placeCursorOnFirstModule() {
t.initialized = true
}
} else if t.cursorIndex < 0 {
placeCursorOnFirstModule()
}
t.setStart(height)
}
Expand Down

0 comments on commit 45bc7a6

Please sign in to comment.