Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom on-select triggers file preview twice #1333

Closed
tex opened this issue Jul 5, 2023 · 4 comments · Fixed by #1335
Closed

custom on-select triggers file preview twice #1333

tex opened this issue Jul 5, 2023 · 4 comments · Fixed by #1335

Comments

@tex
Copy link

tex commented Jul 5, 2023

I have this in lfrc

set statfmt ""

cmd on-select %{{
    s=$(find $fx -type f -maxdepth 1 -ls | awk '{total += $7} END {print total}' | numfmt --to=iec --format='%.2fB')
    printf "> $s"
}}

and I am using kitty to preview images, movies, ...

set previewer ~/.config/lf/lf_kitty_preview
#!/usr/bin/env bash
file=$1
w=$2
h=$3
x=$4
y=$5

filetype="$(file -Lb --mime-type "$file")"

if [[ "$filetype" =~ ^image ]]; then
    kitty +icat --silent --transfer-mode file --place "${w}x${h}@${x}x${y}" "$file"
    exit 1
fi

When I have on-select enabled, then lf shows image preview twice. It causes not pleasant flickering.
Wehn I disable this on-select, then lf shows image preview only once as it should.

@joelim-work
Copy link
Collaborator

Thanks, I managed to reproduce the issue. The problem is that after a % command finishes, it triggers a load command which ends up refreshing the image preview:

lf/app.go

Line 587 in dc2627d

app.ui.exprChan <- &callExpr{"load", nil, 1}

This is the implementation of the load command:

lf/eval.go

Lines 1755 to 1760 in dc2627d

case "load":
if !app.nav.init {
return
}
app.nav.renew()
app.ui.loadFile(app, true)

Note that the true argument for app.ui.loadFile means 'volatile' which will cause the image preview to refresh. I'm very tempted to change this to false, but the load command is used in other places and I'm not sure whether it will break something. At the very least the load following a % command should be non-volatile in my opinion, this has actually been discussed previously in #1281 (comment).

@tex
Copy link
Author

tex commented Jul 6, 2023

That makes sense.

If % command wants to refresh it can issue lf -remote "reload/redraw"...

@joelim-work
Copy link
Collaborator

In my opinion load should still be called after a % command, since it can theoretically do anything, including making changes to files. However it shouldn't refresh image previews unless there has been such a change. Anyway I have submitted a PR #1335, you are welcome to try it out and see if it works for you.

@tex
Copy link
Author

tex commented Jul 6, 2023

This works for me, tested it and all is perfect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants