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 29539f7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
5 changes: 2 additions & 3 deletions internal/tui/explorer/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ type node interface {
}

type dirNode struct {
path string
root bool
closed bool
path string
root bool
}

func (d dirNode) ID() any {
Expand Down
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 29539f7

Please sign in to comment.