From a7f7e84e81d12d67ed8ce270fac08e056beaf15a Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Tue, 21 Oct 2025 21:46:19 +1100 Subject: [PATCH] Handle nav resizes (#2218) * Handle nav resizes * Update `CHANGELOG.md` --- CHANGELOG.md | 3 ++- client.go | 2 +- eval.go | 17 ++++------------- nav.go | 21 +++++++++++++++++++-- ui.go | 1 - 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ec33ce5..f25d5242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - A bug where the `source` command does not show an error message upon failure is now fixed (#2189). - The `addcustominfo` command as well as the `cleaner` and `previewer` options now support file completions (#2198) (#2211). - A bug where an empty `custom` info property would still take up space is now fixed (#2208). -- A bug where setting `drawbox` could lead to scrolling outside the view is now fixed (#2210). +- A bug where setting `drawbox` could lead to scrolling outside the view is now fixed (#2210) (#2218). +- The preview cache is now not cleared when setting `ratios` to its current value (#2218). ## [r38](https://github.com/gokcehan/lf/releases/tag/r38) diff --git a/client.go b/client.go index 0b9cab73..b1473c7f 100644 --- a/client.go +++ b/client.go @@ -52,7 +52,7 @@ func run() { screen.EnablePaste() ui := newUI(screen) - nav := newNav(ui.wins[0].h) + nav := newNav(ui) app := newApp(ui, nav) if err := nav.sync(); err != nil { diff --git a/eval.go b/eval.go index 2e5705b3..077e009b 100644 --- a/eval.go +++ b/eval.go @@ -90,10 +90,7 @@ func (e *setExpr) eval(app *app, args []string) { err = applyBoolOpt(&gOpts.drawbox, e) if err == nil { app.ui.renew() - if app.nav.height != app.ui.wins[0].h { - app.nav.height = app.ui.wins[0].h - clear(app.nav.regCache) - } + app.nav.resize(app.ui) app.ui.loadFile(app, true) } case "hidden", "nohidden", "hidden!": @@ -346,7 +343,7 @@ func (e *setExpr) eval(app *app, args []string) { } gOpts.ratios = rats app.ui.wins = getWins(app.ui.screen) - clear(app.nav.regCache) + app.nav.resize(app.ui) app.ui.loadFile(app, true) case "rulerfmt": gOpts.rulerfmt = e.val @@ -1285,15 +1282,9 @@ func (e *callExpr) eval(app *app, args []string) { if !app.nav.init { return } - app.ui.renew() app.ui.screen.Sync() - if app.nav.height != app.ui.wins[0].h { - app.nav.height = app.ui.wins[0].h - clear(app.nav.regCache) - } - for _, dir := range app.nav.dirs { - dir.boundPos(app.nav.height) - } + app.ui.renew() + app.nav.resize(app.ui) app.ui.sxScreen.forceClear = true app.ui.loadFile(app, true) onRedraw(app) diff --git a/nav.go b/nav.go index e4e11d7a..2b40c9f6 100644 --- a/nav.go +++ b/nav.go @@ -470,6 +470,7 @@ type nav struct { tags map[string]string selectionInd int height int + previewWidth int find string findBack bool search string @@ -582,7 +583,7 @@ func (nav *nav) getDirs(wd string) { nav.dirs = dirs } -func newNav(height int) *nav { +func newNav(ui *ui) *nav { nav := &nav{ copyJobsChan: make(chan int, 1024), copyBytesChan: make(chan int64, 1024), @@ -602,12 +603,12 @@ func newNav(height int) *nav { selections: make(map[string]int), tags: make(map[string]string), selectionInd: 0, - height: height, previewTimer: time.NewTimer(0), jumpList: make([]string, 0), jumpListInd: -1, } + nav.resize(ui) return nav } @@ -670,6 +671,22 @@ func (nav *nav) reload() error { return nil } +func (nav *nav) resize(ui *ui) { + previewWin := ui.wins[len(ui.wins)-1] + if previewWin.h == nav.height && previewWin.w == nav.previewWidth { + return + } + + nav.height = previewWin.h + nav.previewWidth = previewWin.w + + for _, dir := range nav.dirs { + dir.boundPos(nav.height) + } + + clear(nav.regCache) +} + func (nav *nav) position() { if !nav.init { return diff --git a/ui.go b/ui.go index 9e7ebfe7..1b1376ce 100644 --- a/ui.go +++ b/ui.go @@ -1720,7 +1720,6 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr { return &callExpr{"cd", []string{dir.path}, 1} } case *tcell.EventResize: - clear(nav.regCache) return &callExpr{"redraw", nil, 1} case *tcell.EventError: log.Printf("Got EventError: '%s' at %s", tev.Error(), tev.When())