gokcehan / lf

Terminal file manager
MIT License
7.69k stars 326 forks source link

custom on-select triggers file preview twice #1333

Closed tex closed 1 year ago

tex commented 1 year ago

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 commented 1 year ago

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: https://github.com/gokcehan/lf/blob/dc2627de23647b0a0d1fa13d4c039ac075db175c/app.go#L587

This is the implementation of the load command: https://github.com/gokcehan/lf/blob/dc2627de23647b0a0d1fa13d4c039ac075db175c/eval.go#L1755-L1760

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 https://github.com/gokcehan/lf/pull/1281#issuecomment-1575444672.

tex commented 1 year ago

That makes sense.

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

joelim-work commented 1 year ago

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 commented 1 year ago

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