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

Ability to scroll list by count? #569

Open
ibhagwan opened this issue Dec 15, 2024 · 4 comments
Open

Ability to scroll list by count? #569

ibhagwan opened this issue Dec 15, 2024 · 4 comments
Labels
feature New feature or request

Comments

@ibhagwan
Copy link

Feature Description

Ty @Saghen for this wonderful plugin!

I might be missing something but I also looked at the code and couldn't find an equivalent for documentation scroll up|down for the item list.

The use case is using <C-b>|<C-f> to scroll the item list back/forward, perhaps something like #382 but for select_{next|prev}?

keymap = {
  ['<C-b>'] = { function(cmp) cmp.select_prev({ count = 10 }) end },
  ['<C-f>'] = { function(cmp) cmp.select_next({ count = 10 }) end },
@ibhagwan ibhagwan added the feature New feature or request label Dec 15, 2024
@iurimateus
Copy link

iurimateus commented Dec 15, 2024

quick workaround

local function select_next_idx(idx, dir)
  dir = dir or 1

  local list = require "blink.cmp.completion.list"
  if #list.items == 0 then
    return
  end

  local target_idx
  -- haven't selected anything yet
  if list.selected_item_idx == nil then
    if dir == 1 then
      target_idx = idx
    else
      target_idx = #list.items - idx
    end
  elseif list.selected_item_idx == #list.items then
    if dir == 1 then
      target_idx = 1
    else
      target_idx = #list.items - idx
    end
  elseif list.selected_item_idx == 1 and dir == -1 then
    target_idx = #list.items - idx
  else
    target_idx = list.selected_item_idx + (idx * dir)
  end

  -- clamp
  if target_idx < 1 then
    target_idx = 1
  elseif target_idx > #list.items then
    target_idx = #list.items
  end

  list.select(target_idx)
end
keymap = {
  ["<PageDown>"] = {
    function(cmp)
      if not cmp.is_visible() then
        return
      end
      vim.schedule(function()
        select_next_idx(3)
      end)
      return true
    end,
    "fallback",
  },
  ["<PageUp>"] = {
    function(cmp)
      if not cmp.is_visible() then
        return
      end
      vim.schedule(function()
        select_next_idx(3, -1)
      end)
      return true
    end,
    "fallback",
  },
}

@Saghen
Copy link
Owner

Saghen commented Dec 17, 2024

Would you expect this to respect completion.list.cycle?

@ibhagwan
Copy link
Author

Would you expect this to respect completion.list.cycle?

I'm not sure, either way is fine, your call :-)

@brunobmello25
Copy link

Would you expect this to respect completion.list.cycle?

I believe the more sane default would be to respect it, but maybe it could be a setup parameter?

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

No branches or pull requests

4 participants