On browser and file_browser screens, focus the first item when appearing

custom
Rockwell Schrock 3 months ago
parent ddcd06dbca
commit abf13d4ec1
No known key found for this signature in database
GPG Key ID: 528442AF0A5E86BF
  1. 1
      lua/browser.lua
  2. 1
      lua/file_browser.lua
  3. 8
      lua/widgets.lua

@ -118,6 +118,7 @@ return screen:new {
end
widgets.InfiniteList(self.root, self.iterator, {
focus_first_item = true,
get_icon = get_icon_func,
callback = function(item)
return function()

@ -59,6 +59,7 @@ return screen:new {
end
widgets.InfiniteList(self.root, self.iterator, {
focus_first_item = true,
callback = function(item)
return function()
local is_dir = item:is_directory()

@ -306,10 +306,11 @@ function widgets.InfiniteList(parent, iterator, opts)
fwd_iterator:prev()
end
local function add_item(item, index)
local function add_item(item, index, item_opts)
if not item then
return
end
item_opts = item_opts or {}
local this_item = index
local add_to_top = false
if this_item < first_index then
@ -325,6 +326,9 @@ function widgets.InfiniteList(parent, iterator, opts)
if add_to_top then
btn:move_to_index(0)
end
if item_opts.focus then
btn:focus()
end
-- opts.callback should take an item and return a function matching the arg of onClicked
if opts.callback then
btn:onClicked(opts.callback(item))
@ -361,7 +365,7 @@ function widgets.InfiniteList(parent, iterator, opts)
if not val then
break
end
add_item(val, idx)
add_item(val, idx, { focus = (opts.focus_first_item and idx == 0) })
end
return infinite_list

Loading…
Cancel
Save