diff --git a/internal/browser/manager.go b/internal/browser/manager.go index aa6ed6a..d8f341b 100644 --- a/internal/browser/manager.go +++ b/internal/browser/manager.go @@ -27,7 +27,10 @@ func NewBrowserManager(state *BrowserState, wp *pool.WorkerPool, fs pool.FileSys func (bm *BrowserManager) NavigateTo(dirPath string) { fmt.Printf("NavigateTo: dirPath=%s, state.CurrentPath=%s\n", dirPath, bm.state.CurrentPath) - + + // Save the previous path so we can restore it on navigation failure. + bm.state.History = append(bm.state.History, bm.state.CurrentPath) + bm.state.CurrentPath = dirPath navigateToDirectory(bm.state, dirPath) bm.state.Loading = true @@ -159,9 +162,22 @@ func (bm *BrowserManager) handleLoadPagesSuccess(result pool.Result) { func (bm *BrowserManager) handleError(result pool.Result) { fmt.Printf("handleError: TaskType=%d, Error=%v\n", result.TaskType, result.Error) bm.state.Loading = false - // For now, just reset the state or log the error. - // In production, we'd show a toast or error message. - if bm.state.CurrentPath == bm.state.CurrentPath { - bm.state.Reset() + + // If the failed task was a BuildIndex (directory navigation), restore + // the previous path so the user is sent back to where they were. + if result.TaskType == pool.TypeBuildIndex && len(bm.state.History) > 0 { + prevPath := bm.state.History[len(bm.state.History)-1] + bm.state.History = bm.state.History[:len(bm.state.History)-1] + bm.state.CurrentPath = prevPath + navigateToDirectory(bm.state, prevPath) + // Re-dispatch the build index for the previous directory so the + // browser renders the old contents again. + task := pool.NewBuildIndexTask(prevPath, bm.fs) + bm.workerPool.Dispatch(task) + return } + + // For other errors, just reset the state or log the error. + // In production, we'd show a toast or error message. + bm.state.Reset() } diff --git a/internal/browser/types.go b/internal/browser/types.go index 51f610f..cdb71c0 100644 --- a/internal/browser/types.go +++ b/internal/browser/types.go @@ -30,6 +30,7 @@ type Page struct { type BrowserState struct { // Navigation CurrentPath string // Currently browsed directory (relative to root) + History []string // Path history for navigation ScrollOffset float64 // Vertical scroll offset in pixels (per-pixel scrolling) EntryHeight float64 // Height of a single entry in pixels VisibleCount int // Number of entries currently visible