Skip to content

Commit 45bc7a6

Browse files
committed
fix: always try to put cursor on first module
1 parent 17dba76 commit 45bc7a6

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

Diff for: internal/tui/explorer/tracker.go

+19-10
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,32 @@ func (t *tracker) reindex(tree *tree, height int) {
4141
t.doReindex(tree)
4242
t.selector.reindex(t.nodes)
4343

44-
// When pug first starts up, for the user's convenience we want the cursor
45-
// to be on the first module. Because modules are added asynchronously, a
46-
// semaphore detects whether the cursor has been set to the first module, to
47-
// ensure this is only done once.
48-
if !t.initialized {
44+
placeCursorOnFirstModule := func() bool {
4945
for i, n := range t.nodes {
5046
if _, ok := n.(moduleNode); ok {
5147
t.cursorNode = t.nodes[i]
5248
t.cursorIndex = i
53-
t.initialized = true
54-
break
49+
return true
5550
}
5651
}
52+
// If no modules found then set cursor on first node
53+
if t.cursorIndex < 0 {
54+
t.cursorNode = t.nodes[0]
55+
t.cursorIndex = 0
56+
}
57+
return false
5758
}
58-
if t.cursorIndex < 0 {
59-
t.cursorNode = t.nodes[0]
60-
t.cursorIndex = 0
59+
60+
// When pug first starts up, for the user's convenience we want the cursor
61+
// to be on the first module. Because modules are added asynchronously, a
62+
// semaphore detects whether the cursor has been set to the first module, to
63+
// ensure this is only done once.
64+
if !t.initialized {
65+
if placeCursorOnFirstModule() {
66+
t.initialized = true
67+
}
68+
} else if t.cursorIndex < 0 {
69+
placeCursorOnFirstModule()
6170
}
6271
t.setStart(height)
6372
}

0 commit comments

Comments
 (0)