mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
feat(picker.list): list:view is sets the cursor with an optional topline
This commit is contained in:
parent
ae44066826
commit
859ab6d63e
2 changed files with 13 additions and 6 deletions
|
@ -98,6 +98,7 @@ function M.loclist(picker)
|
|||
local sel = picker:selected()
|
||||
local items = #sel > 0 and sel or picker.finder.items
|
||||
setqflist(items, { win = picker.parent_win })
|
||||
setqflist(items, { win = picker.main })
|
||||
end
|
||||
|
||||
function M.copy(_, item)
|
||||
|
@ -284,20 +285,17 @@ end
|
|||
|
||||
function M.list_scroll_top(picker)
|
||||
local cursor = picker.list.cursor
|
||||
picker.list:scroll(picker.list.cursor, true)
|
||||
picker.list:move(cursor, true)
|
||||
picker.list:view(cursor, cursor)
|
||||
end
|
||||
|
||||
function M.list_scroll_bottom(picker)
|
||||
local cursor = picker.list.cursor
|
||||
picker.list:scroll(picker.list.cursor - picker.list:height() + 1, true)
|
||||
picker.list:move(cursor, true)
|
||||
picker.list:view(cursor, picker.list.cursor - picker.list:height() + 1)
|
||||
end
|
||||
|
||||
function M.list_scroll_center(picker)
|
||||
local cursor = picker.list.cursor
|
||||
picker.list:scroll(picker.list.cursor - math.ceil(picker.list:height() / 2) + 1, true)
|
||||
picker.list:move(cursor, true)
|
||||
picker.list:view(cursor, picker.list.cursor - math.ceil(picker.list:height() / 2) + 1)
|
||||
end
|
||||
|
||||
function M.list_scroll_down(picker)
|
||||
|
|
|
@ -89,6 +89,15 @@ function M.new(picker)
|
|||
return self
|
||||
end
|
||||
|
||||
---@param cursor number
|
||||
---@param topline? number
|
||||
function M:view(cursor, topline)
|
||||
if topline then
|
||||
self:scroll(topline, true, false)
|
||||
end
|
||||
self:move(cursor, true)
|
||||
end
|
||||
|
||||
---@param idx number
|
||||
function M:idx2row(idx)
|
||||
local ret = idx - self.top + 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue