Skip to content

Commit

Permalink
feat: added methods that can be mapped for scrolling the hover/signat…
Browse files Browse the repository at this point in the history
…ureHelp windows
  • Loading branch information
folke committed Oct 26, 2022
1 parent 5bd6e30 commit a6ad24e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lua/noice/source/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ function M.setup()
end
end

function M.scroll(delta)
for _, kind in ipairs({ M.kinds.hover, M.kinds.signature }) do
local message = M.get(kind)
local win = message:win()
if win then
Util.nui.scroll(win, delta)
return
end
end
end

---@param message NoiceMessage
function M.augroup(message)
return "noice_lsp_" .. message.id
Expand Down
16 changes: 16 additions & 0 deletions lua/noice/util/nui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,20 @@ function M.anchor(width, height)
return anchor
end

function M.scroll(win, delta)
local info = vim.fn.getwininfo(win)[1] or {}
local top = info.topline or 1
local buf = vim.api.nvim_win_get_buf(win)
top = top + delta
top = math.max(top, 1)
top = math.min(top, M.win_buf_height(win) - info.height + 1)

vim.defer_fn(function()
vim.api.nvim_buf_call(buf, function()
vim.api.nvim_command("normal! " .. top .. "zt")
vim.cmd([[do WinScrolled]])
end)
end, 0)
end

return M
2 changes: 2 additions & 0 deletions lua/noice/view/nui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ function NuiView:update_options()
},
win_options = {
foldenable = false,
scrolloff = 0,
sidescrolloff = 0,
},
}, self._opts, self:get_layout())

Expand Down

0 comments on commit a6ad24e

Please sign in to comment.