Fix directory navigation and path initialization

- Initialize browser path to the actual startup directory instead of '/'
- Improve '..' navigation to be relative to the filesystem root
- Fix path duplication issues by avoiding redundant absolute path joining
This commit is contained in:
gmp
2026-06-05 13:43:27 -04:00
parent 80c2dfd743
commit beae5fc026
4 changed files with 42 additions and 15 deletions
+17 -6
View File
@@ -3,8 +3,6 @@ package browser
import (
"fmt"
"path/filepath"
"strings"
"pad/internal/ui"
)
@@ -81,11 +79,24 @@ func HandleBrowserTap(bm *BrowserManager, s *BrowserState, index int) {
// Navigate into directory or up
var newPath string
if entry.Name == ".." {
newPath = filepath.Dir(s.CurrentPath)
// If we are at the root (".") stay there
if s.CurrentPath == "." || s.CurrentPath == "" {
newPath = "."
} else {
// Get parent directory
parent := filepath.Dir(s.CurrentPath)
if parent == "." || parent == "/" {
newPath = "."
} else {
newPath = parent
}
}
} else {
newPath = filepath.Join(s.CurrentPath, entry.Name)
if !strings.HasPrefix(newPath, "/") {
newPath = "/" + newPath
// Join child entry name
if s.CurrentPath == "." {
newPath = entry.Name
} else {
newPath = filepath.Join(s.CurrentPath, entry.Name)
}
}
bm.NavigateTo(newPath)
+6 -3
View File
@@ -26,7 +26,8 @@ func NewBrowserManager(state *BrowserState, wp *pool.WorkerPool, fs pool.FileSys
}
func (bm *BrowserManager) NavigateTo(dirPath string) {
fmt.Printf("NavigateTo: %s\n", dirPath)
fmt.Printf("NavigateTo: dirPath=%s, state.CurrentPath=%s\n", dirPath, bm.state.CurrentPath)
bm.state.CurrentPath = dirPath
navigateToDirectory(bm.state, dirPath)
bm.state.Loading = true
@@ -86,7 +87,6 @@ func (bm *BrowserManager) HandleResult(result pool.Result) {
}
func (bm *BrowserManager) handleBuildIndexSuccess(result pool.Result) {
fmt.Printf("handleBuildIndexSuccess: TotalEntries=%d\n", len(result.Data.([]types.DirEntry)))
bm.state.Loading = false
// In the mock implementation, BuildIndexTask returns []types.DirEntry.
@@ -95,7 +95,9 @@ func (bm *BrowserManager) handleBuildIndexSuccess(result pool.Result) {
var browserEntries []Entry
// Add ".." entry if not at root
if bm.state.CurrentPath != "/" && bm.state.CurrentPath != "." {
// We check against "/" specifically. "." is just a relative path for current dir,
// which still has a parent.
if bm.state.CurrentPath != "/" && bm.state.CurrentPath != "" {
browserEntries = append(browserEntries, Entry{
Path: filepath.Dir(bm.state.CurrentPath),
Name: "..",
@@ -107,6 +109,7 @@ func (bm *BrowserManager) handleBuildIndexSuccess(result pool.Result) {
for _, e := range entries {
info, _ := e.Info()
fmt.Printf("Adding entry: %s\n", e.Name())
browserEntries = append(browserEntries, Entry{
Path: filepath.Join(bm.state.CurrentPath, e.Name()),
Name: e.Name(),