feat: apply loading message delay for directories (#2410)
* refactor preview timer * add preview timer for directory * adjust times * typo * create constant for preview loading delay * Update `CHANGELOG.md`
This commit is contained in:
1 parent
6ec60cf9d8
commit
fd2babd72e
4 files changed
+25
-22
No files matched your search
@@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
- Emoji sequences containing Zero Width Joiner characters are now displayed as a single combined glyph (#2286).
|
||||
- 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).
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -29,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
- The `select` command can now select files immediately after creation as part of a script (#2377).
|
||||
- The `on-load` hook command now ignores `.git` directories to reduce flicker and repeated `on-load` triggers (#2382).
|
||||
- Preview messages like `empty` or `loading...` have their alignment improved (#2400).
|
||||
- A bug where the `loading...` message was not displayed for volatile previews after the first time is now fixed (#2410).
|
||||
|
||||
## [r41](https://github.com/gokcehan/lf/releases/tag/r41)
|
||||
|
||||
|
||||
@@ -509,7 +509,6 @@ func (app *app) loop() {
|
||||
app.nav.renew()
|
||||
app.ui.loadFile(app, false)
|
||||
case <-app.nav.previewTimer.C:
|
||||
app.nav.previewLoading = true
|
||||
app.ui.draw(app.nav)
|
||||
case <-app.nav.preloadTimer.C:
|
||||
app.nav.preload()
|
||||
|
||||
@@ -478,7 +478,6 @@ type nav struct {
|
||||
prevFilter []string
|
||||
volatilePreview bool
|
||||
previewTimer *time.Timer
|
||||
previewLoading bool
|
||||
preloadTimer *time.Timer
|
||||
jumpList []string
|
||||
jumpListInd int
|
||||
@@ -495,6 +494,7 @@ func (nav *nav) getDir(path string) *dir {
|
||||
|
||||
d := &dir{
|
||||
loading: true,
|
||||
loadTime: time.Now(),
|
||||
path: path,
|
||||
sortby: getSortBy(path),
|
||||
dircounts: getDirCounts(path),
|
||||
@@ -855,7 +855,6 @@ func (nav *nav) preload() {
|
||||
}
|
||||
}
|
||||
|
||||
nav.startPreview()
|
||||
for i := nav.height / 2; i >= 1; i-- {
|
||||
doPreload(dir.ind - i)
|
||||
doPreload(dir.ind + i)
|
||||
@@ -952,7 +951,6 @@ func (nav *nav) loadReg(path string, volatile bool) *reg {
|
||||
if !ok || (!gOpts.preload && r.loading) {
|
||||
r = ®{loading: true, loadTime: time.Now(), path: path}
|
||||
nav.regCache[path] = r
|
||||
nav.startPreview()
|
||||
if gOpts.preload {
|
||||
select {
|
||||
case nav.preloadChan <- path:
|
||||
@@ -965,7 +963,10 @@ func (nav *nav) loadReg(path string, volatile bool) *reg {
|
||||
}
|
||||
|
||||
if volatile && r.volatile {
|
||||
nav.startPreview()
|
||||
if !gOpts.preload {
|
||||
r.loadTime = time.Now()
|
||||
r.loading = true
|
||||
}
|
||||
nav.previewChan <- path
|
||||
}
|
||||
|
||||
@@ -989,17 +990,10 @@ func (nav *nav) checkReg(reg *reg) {
|
||||
|
||||
if s.ModTime().After(reg.loadTime) {
|
||||
reg.loadTime = now
|
||||
nav.startPreview()
|
||||
nav.previewChan <- reg.path
|
||||
}
|
||||
}
|
||||
|
||||
func (nav *nav) startPreview() {
|
||||
nav.previewTimer.Stop()
|
||||
nav.previewLoading = false
|
||||
nav.previewTimer.Reset(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
func (nav *nav) sort() {
|
||||
for _, path := range nav.dirPaths {
|
||||
dir := nav.getDir(path)
|
||||
|
||||
@@ -21,6 +21,8 @@ import (
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
const previewLoadingDelay = 100 * time.Millisecond
|
||||
|
||||
type win struct {
|
||||
w, h, x, y int
|
||||
}
|
||||
@@ -121,11 +123,13 @@ func (win *win) printMsg(screen tcell.Screen, s string) {
|
||||
win.print(screen, pad, 0, st, s)
|
||||
}
|
||||
|
||||
func (win *win) printReg(screen tcell.Screen, reg *reg, previewLoading bool, sxs *sixelScreen) {
|
||||
func (win *win) printReg(screen tcell.Screen, reg *reg, sxs *sixelScreen, previewTimer *time.Timer) {
|
||||
switch {
|
||||
case reg.loading:
|
||||
if previewLoading {
|
||||
if time.Since(reg.loadTime) > previewLoadingDelay {
|
||||
win.printMsg(screen, "loading...")
|
||||
} else {
|
||||
previewTimer.Reset(previewLoadingDelay)
|
||||
}
|
||||
case reg.sixel:
|
||||
sxs.printSixel(win, screen, reg)
|
||||
@@ -234,7 +238,7 @@ type dirStyle struct {
|
||||
role dirRole
|
||||
}
|
||||
|
||||
func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirStyle) {
|
||||
func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirStyle, previewTimer *time.Timer) {
|
||||
if win.w < 5 || dir == nil {
|
||||
return
|
||||
}
|
||||
@@ -242,12 +246,16 @@ func (win *win) printDir(ui *ui, dir *dir, context *dirContext, dirStyle *dirSty
|
||||
fileslen := len(dir.files)
|
||||
|
||||
switch {
|
||||
case dir.loading && fileslen == 0:
|
||||
if time.Since(dir.loadTime) > previewLoadingDelay {
|
||||
win.printMsg(ui.screen, "loading...")
|
||||
} else {
|
||||
previewTimer.Reset(previewLoadingDelay)
|
||||
}
|
||||
return
|
||||
case dir.noPerm:
|
||||
win.printMsg(ui.screen, "permission denied")
|
||||
return
|
||||
case dir.loading && fileslen == 0:
|
||||
win.printMsg(ui.screen, "loading...")
|
||||
return
|
||||
case fileslen == 0:
|
||||
win.printMsg(ui.screen, "empty")
|
||||
return
|
||||
@@ -1000,13 +1008,13 @@ func (ui *ui) drawPreview(nav *nav, context *dirContext) {
|
||||
if gOpts.preview {
|
||||
if curr.isPreviewable() {
|
||||
if reg, ok := nav.regCache[curr.path]; ok {
|
||||
win.printReg(ui.screen, reg, nav.previewLoading, &ui.sxScreen)
|
||||
win.printReg(ui.screen, reg, &ui.sxScreen, nav.previewTimer)
|
||||
}
|
||||
} else if curr.IsDir() {
|
||||
ui.sxScreen.lastFile = ""
|
||||
dir := nav.getDir(curr.path)
|
||||
dirStyle := &dirStyle{colors: ui.styles, icons: ui.icons, role: Preview}
|
||||
win.printDir(ui, dir, context, dirStyle)
|
||||
win.printDir(ui, dir, context, dirStyle, nav.previewTimer)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1111,8 +1119,8 @@ func (ui *ui) draw(nav *nav) {
|
||||
role = Active
|
||||
}
|
||||
if dir := ui.dirOfWin(nav, i); dir != nil {
|
||||
ui.wins[i].printDir(ui, dir, &context,
|
||||
&dirStyle{colors: ui.styles, icons: ui.icons, role: role})
|
||||
dirStyle := &dirStyle{colors: ui.styles, icons: ui.icons, role: role}
|
||||
ui.wins[i].printDir(ui, dir, &context, dirStyle, nav.previewTimer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user