Handle nav resizes (#2218)

* Handle nav resizes

* Update `CHANGELOG.md`
This commit is contained in:
Joe Lim authored and GitHub committed 2025-10-21 21:46:19 +11:00
1 parent 7b6b6da100
commit a7f7e84e81
5 files changed
+26 -18

No files matched your search

+2 -1
View File
@@ -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). - 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). - 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 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) ## [r38](https://github.com/gokcehan/lf/releases/tag/r38)
+1 -1
View File
@@ -52,7 +52,7 @@ func run() {
screen.EnablePaste() screen.EnablePaste()
ui := newUI(screen) ui := newUI(screen)
nav := newNav(ui.wins[0].h) nav := newNav(ui)
app := newApp(ui, nav) app := newApp(ui, nav)
if err := nav.sync(); err != nil { if err := nav.sync(); err != nil {
+4 -13
View File
@@ -90,10 +90,7 @@ func (e *setExpr) eval(app *app, args []string) {
err = applyBoolOpt(&gOpts.drawbox, e) err = applyBoolOpt(&gOpts.drawbox, e)
if err == nil { if err == nil {
app.ui.renew() app.ui.renew()
if app.nav.height != app.ui.wins[0].h { app.nav.resize(app.ui)
app.nav.height = app.ui.wins[0].h
clear(app.nav.regCache)
}
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
} }
case "hidden", "nohidden", "hidden!": case "hidden", "nohidden", "hidden!":
@@ -346,7 +343,7 @@ func (e *setExpr) eval(app *app, args []string) {
} }
gOpts.ratios = rats gOpts.ratios = rats
app.ui.wins = getWins(app.ui.screen) app.ui.wins = getWins(app.ui.screen)
clear(app.nav.regCache) app.nav.resize(app.ui)
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
case "rulerfmt": case "rulerfmt":
gOpts.rulerfmt = e.val gOpts.rulerfmt = e.val
@@ -1285,15 +1282,9 @@ func (e *callExpr) eval(app *app, args []string) {
if !app.nav.init { if !app.nav.init {
return return
} }
app.ui.renew()
app.ui.screen.Sync() app.ui.screen.Sync()
if app.nav.height != app.ui.wins[0].h { app.ui.renew()
app.nav.height = app.ui.wins[0].h app.nav.resize(app.ui)
clear(app.nav.regCache)
}
for _, dir := range app.nav.dirs {
dir.boundPos(app.nav.height)
}
app.ui.sxScreen.forceClear = true app.ui.sxScreen.forceClear = true
app.ui.loadFile(app, true) app.ui.loadFile(app, true)
onRedraw(app) onRedraw(app)
+19 -2
View File
@@ -470,6 +470,7 @@ type nav struct {
tags map[string]string tags map[string]string
selectionInd int selectionInd int
height int height int
previewWidth int
find string find string
findBack bool findBack bool
search string search string
@@ -582,7 +583,7 @@ func (nav *nav) getDirs(wd string) {
nav.dirs = dirs nav.dirs = dirs
} }
func newNav(height int) *nav { func newNav(ui *ui) *nav {
nav := &nav{ nav := &nav{
copyJobsChan: make(chan int, 1024), copyJobsChan: make(chan int, 1024),
copyBytesChan: make(chan int64, 1024), copyBytesChan: make(chan int64, 1024),
@@ -602,12 +603,12 @@ func newNav(height int) *nav {
selections: make(map[string]int), selections: make(map[string]int),
tags: make(map[string]string), tags: make(map[string]string),
selectionInd: 0, selectionInd: 0,
height: height,
previewTimer: time.NewTimer(0), previewTimer: time.NewTimer(0),
jumpList: make([]string, 0), jumpList: make([]string, 0),
jumpListInd: -1, jumpListInd: -1,
} }
nav.resize(ui)
return nav return nav
} }
@@ -670,6 +671,22 @@ func (nav *nav) reload() error {
return nil 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() { func (nav *nav) position() {
if !nav.init { if !nav.init {
return return
-1
View File
@@ -1720,7 +1720,6 @@ func (ui *ui) readNormalEvent(ev tcell.Event, nav *nav) expr {
return &callExpr{"cd", []string{dir.path}, 1} return &callExpr{"cd", []string{dir.path}, 1}
} }
case *tcell.EventResize: case *tcell.EventResize:
clear(nav.regCache)
return &callExpr{"redraw", nil, 1} return &callExpr{"redraw", nil, 1}
case *tcell.EventError: case *tcell.EventError:
log.Printf("Got EventError: '%s' at %s", tev.Error(), tev.When()) log.Printf("Got EventError: '%s' at %s", tev.Error(), tev.When())