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

feat(menu): simplify calculations for selection #120

Merged
merged 1 commit into from
Nov 1, 2024

Conversation

vdbe
Copy link
Contributor

@vdbe vdbe commented Nov 1, 2024

When using a negative count for Menu:select_next don't go into negative indices instead rollover to the last entry.

This simplifies for example the following logic:

local next = function(direction, key)
  return function()
    if care.api.is_open() then
      -- Post PR
      care.api.select_next(direction)

      -- Pre PR
      -- if direction >= 0 then
      --   care.api.select_next(direction)
      -- else
      --   care.api.select_prev(-direction)
      -- end
    elseif vim.snippet.active { direction = direction } then
      vim.snippet.jump(direction)
    elseif key ~= nil then
      vim.api.nvim_feedkeys(vim.keycode(key), "n", false)
    else
      care.api.complete()
    end
  end
end

vim.keymap.set("i", "<c-n>", next(1))
vim.keymap.set("i", "<c-p>", next(-1))

@vdbe vdbe requested a review from max397574 as a code owner November 1, 2024 11:16
lua/care/menu/init.lua Outdated Show resolved Hide resolved
@vdbe vdbe force-pushed the feat/menu/select_next/negative branch from 643f6b1 to 6466e49 Compare November 1, 2024 11:20
lua/care/init.lua Outdated Show resolved Hide resolved
lua/care/menu/init.lua Outdated Show resolved Hide resolved
lua/care/menu/init.lua Outdated Show resolved Hide resolved
lua/care/menu/init.lua Outdated Show resolved Hide resolved
Copy link
Owner

@max397574 max397574 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice if you could squash and adapt the commit message and pr title to the actual changed (e.g. feat(menu): simplify calculations for selection)
so we get a nice commit history

When using a negative count for `Menu:select_next` don't go into
negative indices instead rollover to the last entry.

Co-authored-by: max397574 <[email protected]>
@vdbe vdbe force-pushed the feat/menu/select_next/negative branch from 429c6f8 to 36bcd88 Compare November 1, 2024 12:33
@vdbe vdbe changed the title feat(window): Menu:select_next negative count feat(menu): simplify calculations for selection Nov 1, 2024
@max397574
Copy link
Owner

thank you for your contribution

@max397574 max397574 merged commit dd7fa89 into max397574:main Nov 1, 2024
1 of 5 checks passed
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 this pull request may close these issues.

2 participants