Closed dodgerblue closed 1 year ago
We used to use --line-range
in the past, but it was removed in 4145f53f3d343c389ff974b1f1a68eeb39fba18b, which made it possible to scroll upwards. To allow scrolling inside the preview window (using mouse scroll), the script now prints the whole file.
Thank you for the explanation and the reference, @junegunn ! Would you be willing to consider a change where --line-range
is used based on an environment variable? Personally, I'm more interested in getting the quick glimpse of the location in the preview, rather than scrolling towards it. I'll also look into 'pre-scrolling' the window programatically to the center when displaying the preview.
I'm not sure what you're trying to do here. The preview window of fzf already scrolls to the line and display the line at the center of the screen (e.g. '--preview-window', '+{2}-/2'
). Ag, Rg, Buffers, BTags, etc.
Ah, thank you for the pointer! I looked into the Ag
& co definitions and got what you mean. It's what I had in mind when I mentioned 'pre-scroll'.
In my use-case, I'm defining a new command via fzf#run
for browsing tags, but this one's based on GNU global. For this, I'm using source: global -cT
, which simply prints the symbol names matching a prefix. When displaying the preview, I'm doing some extra processing to figure out the file and line, and I'm using with_preview('placeholder': "$(global -t {} | tail -n 1 | ...)")
. This works fine when displaying the preview window contents, but unfortunately I don't have the file and line ready before running the fzf command, so that I can pass the scroll position to --preview-window
. Changing the source
command to include this extra processing adds some delay to the command (tested only in terminal, haven't found a way to make it work with fzf#run
yet, with all the pipes and escapes), and I can't seem to be able to replace +{2}-/2
with an expression like +{$( ... )}-/2
or +$( ... )-/2
to dynamically compute the position.
I'll look more into it. Maybe there's a fzf feature that supports some extra processing of the entry before it's sent to the preview window, that I don't know about?
Changing the
source
command to include this extra processing adds some delay to the command (tested only in terminal, haven't found a way to make it work withfzf#run
yet, with all the pipes and escapes), and I can't seem to be able to replace+{2}-/2
with an expression like+{$( ... )}-/2
or+$( ... )-/2
to dynamically compute the position.
I see, thanks for the clarification.
Maybe there's a fzf feature that supports some extra processing of the entry before it's sent to the preview window
No, there's no such thing.
bat / batcat supports a
line-range
parameter to specify the range of the file to display. Set the start position based on the provided CENTER variable and FZF_DEFAULT_LINES. The preview window will contain only the lines around the CENTER, not the beginning of the file.For the default awk-based approach, only print the lines that are greater than the start point.
Signed-off-by: Bogdan Purcareata bogdan.purcareata@gmail.com