refactor(completion): clean up popup scroll API

This commit is contained in:
2026-04-17 00:14:55 +02:00
parent 47f36adc21
commit f4d3a35171
2 changed files with 10 additions and 16 deletions
+5 -5
View File
@@ -174,20 +174,20 @@ function M.setup()
end, { expr = true, replace_keycodes = true })
end
scroll_map("<C-d>", function()
popup:scroll_half(vim.keycode("<C-e>"))
popup:scroll("down", Popup.HALF_PAGE)
end)
scroll_map("<C-u>", function()
popup:scroll_half(vim.keycode("<C-y>"))
popup:scroll("up", Popup.HALF_PAGE)
end)
scroll_map("<C-j>", function()
popup:scroll_line(vim.keycode("<C-e>"))
popup:scroll("down", 1)
end)
scroll_map("<C-k>", function()
popup:scroll_line(vim.keycode("<C-y>"))
popup:scroll("up", 1)
end)
vim.keymap.set("i", "<CR>", function()
if vim.fn.pumvisible() ~= 0 then
if popup:is_visible() then
return "<C-y>"
end
return "<CR>"
+5 -11
View File
@@ -135,15 +135,7 @@ function Popup:dispatch_resolve(client, item, ft, pum, word, buf)
end
end
---@param direction string single-line scroll keycode (<C-e> or <C-y>)
function Popup:scroll_line(direction)
self:scroll(direction, 1)
end
---@param direction string
function Popup:scroll_half(direction)
self:scroll(direction, HALF_HEIGHT)
end
Popup.HALF_PAGE = HALF_HEIGHT
---@param content string
---@param pum ow.lsp.completion.Pum
@@ -209,14 +201,16 @@ function Popup:render(content, pum, width)
self:update_indicators()
end
---@param direction string
---@param direction "up" | "down"
---@param count integer
function Popup:scroll(direction, count)
if not self:is_visible() then
return
end
local key = direction == "down" and vim.keycode("<C-e>")
or vim.keycode("<C-y>")
vim.api.nvim_win_call(self.winid, function()
vim.cmd.normal({ args = { count .. direction }, bang = true })
vim.cmd.normal({ args = { count .. key }, bang = true })
end)
self:update_indicators()
end