From 3ec5ee861670069104897a7f3c0604649d887e24 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Tue, 10 Mar 2026 15:24:37 +1100 Subject: [PATCH] feat: change to parent directory if CWD is deleted (#2424) * feat: change to parent directory if CWD is deleted * fix lint warning * Update `CHANGELOG.md` --- CHANGELOG.md | 1 + app.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d307bf67..99000dce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - A new field `.All` is added to the `ruler` file to display the number of all files (i.e. visible + hidden) in the current working directory (#2376). - A new option `numbercursorfmt` is added to further customize the appearance of line numbers (#2395). - The `loading...` message delay of 100 milliseconds for file previews is now applied to directories as well (#2410). +- `lf` will now automatically change to the parent directory if the current directory no longer exists and the `watch` option is enabled (#2424). ### Fixed diff --git a/app.go b/app.go index 0514183f..7f5799cc 100644 --- a/app.go +++ b/app.go @@ -473,6 +473,15 @@ func (app *app) loop() { deletePathRecursive(app.nav.regCache, path) deletePathRecursive(app.nav.dirCache, path) + + for _, dirPath := range app.nav.dirPaths { + if dirPath == path { + if err := app.nav.cd(filepath.Dir(path)); err != nil { + log.Print(err) + } + break + } + } case ev := <-app.ui.evChan: e := app.ui.readEvent(ev, app.nav) if e == nil {