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

Bug: Builtin preview scroll misbehaviors #1525

Closed
2 of 6 tasks
MrConnorKenway opened this issue Nov 14, 2024 · 4 comments
Closed
2 of 6 tasks

Bug: Builtin preview scroll misbehaviors #1525

MrConnorKenway opened this issue Nov 14, 2024 · 4 comments
Labels
bug Something isn't working not planned This will not be worked on

Comments

@MrConnorKenway
Copy link

RTFM Checklist

  • I have searched exisiting issues / discussions
  • I have read the Wiki including the Advanced section
  • I have read man fzf / I am well versed in shell fzf

Operating system

macOS 14.6.1

Shell

zsh

Neovim version (nvim --version)

v0.10.2

Fzf version (fzf --version)

0.55.0 (brew)

Output of :lua print(os.getenv('FZF_DEFAULT_OPTS'))

nil

Is the problem reproducible with mini.sh?

  • My issue is reproducible with mini.sh
  • My issue IS NOT reproducible with mini.sh
  • I have not tested with mini.sh (not relevant, requires LSP, Windows, etc)

Fzf-lua configuration

{
  'ibhagwan/fzf-lua',
  dependencies = { 'nvim-tree/nvim-web-devicons' },
  config = function()
    require('fzf-lua').setup {
      'default-title',
      files = {
        git_icons = false
      },
      winopts = {
        preview = {
          default = 'builtin',
          delay = 10
        }
      },
      previewers = {
        builtin = {
          treesitter = { enable = true }
        }
      },
      keymap = {
        builtin = {
          ['<C-u>'] = 'preview-page-up',
          ['<C-d>'] = 'preview-page-down'
        }
      }
    }
  end
}

Describe the bug / steps to reproduce

Issue 1:

Sometimes preview-half-page-up only scrolls up one line rather than half page.

To reproduce

Execute sh -c "$(curl -s https://raw.githubusercontent.com/ibhagwan/fzf-lua/main/scripts/mini.sh)", run :FzfLua files, and press "shift-arrow down" to scroll down half page, the first line number of preview window becomes 20:
image
Now press "shift-arrow up", the first line becomes 19 instead of 1:
image
Press "shift-arrow up" again, the first line becomes 1.

Issue 2:

Preview-page-up only scrolls up half page instead of whole page. I've check fzf previewer like bat, and the preview scroll is normal.

@MrConnorKenway MrConnorKenway added the bug Something isn't working label Nov 14, 2024
@ibhagwan
Copy link
Owner

Sometimes preview-half-page-up only scrolls up one line rather than half page.
Preview-page-up only scrolls up half page instead of whole page. I've check fzf previewer like bat, and the preview scroll is normal.

That is somewhat by design, the neovim previewer sends ctrl-d|u to the buffer and this is it’s behavior when close to the top of the buffer (unlike ctrl-f|b), I’m not sure why that is but that’s how neovim works, if you wish to fix that it’s better to discuss this upstream.

@ibhagwan ibhagwan added the not planned This will not be worked on label Nov 14, 2024
@MrConnorKenway
Copy link
Author

MrConnorKenway commented Nov 14, 2024

Thanks your fast comment for issue 1. Sorry to bother but I still want to know why I can't scroll a whole page back as I mentioned in issue 2.

@MrConnorKenway
Copy link
Author

MrConnorKenway commented Nov 14, 2024

Oh, another question. In telescope.nvim I can scroll to to the top of buffer using one <C-u>, so telescope does not use neovim's builtin previewer? But their document says that

The default previewers are from now on vim_buffer_ previewers. They use vim buffers for displaying files and use tree-sitter or regex for file highlighting.

I thought this sort of sounds like builtin previewer?

@ibhagwan
Copy link
Owner

Idk what telescope does now exactly but as far as I recall the preview sends ctrl-u/d to scroll, if you want to match Telescope’s behavior change keymap.builtin to preview-half-page-{up|down} (instead of full page which sends ctrl-b/f).

Here’s my original comment in the code for this issue:

-- ctrl-b (page-up) behaves in a non consistent way, unlike ctrl-u, if it can't
-- scroll a full page upwards it won't move the cursor, if the cursor is within
-- the first page it will still move the cursor to the bottom of the page (!?)
-- we therefore need special handling for both scenarios with `ctrl-b`:
-- (1) If the cursor is at line 1, do nothing
-- (2) Else, test the cursor before and after, if the new position is further
-- down the buffer than the original, we're in the first page ,goto line 1
local is_ctrl_b = string.byte(input, 1) == 2
local pos = is_ctrl_b and vim.api.nvim_win_get_cursor(0)
if is_ctrl_b and pos[1] == 1 then return end
vim.cmd([[norm! ]] .. input)
if is_ctrl_b and pos[1] <= vim.api.nvim_win_get_cursor(0)[1] then
vim.api.nvim_win_set_cursor(0, { 1, pos[2] })
end
utils.zz()

I modified the ctrl-b hack to also scroll up to top if the change is just 1 line, it’s not perfect and depending on the size of the preview near the top it will sometimes scroll 2 lines (and only then you can press another scroll to top), although I could fix this to scroll by relative number of lines by manually moving the cursor I won’t think this issue is worth the time, if you’re really bothered by it change the key maps to preview-half-page-{up|down} which don’t have this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working not planned This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants