Large projects can take a long time for the initial scan. This adds some loading text until the initial selection has completed. This will also now schedule the work to collect and sort the candidates to ensure the UI is rendered before with work begins and creates a hanging user experience.
62 lines
1.2 KiB
Lua
62 lines
1.2 KiB
Lua
local window = require "ivy.window"
|
|
local prompt = require "ivy.prompt"
|
|
|
|
local controller = {}
|
|
|
|
controller.items = nil
|
|
controller.callback = nil
|
|
|
|
controller.run = function(items, callback)
|
|
controller.callback = callback
|
|
controller.items = items
|
|
|
|
window.initialize()
|
|
window.set_items { "-- Loading ---" }
|
|
|
|
controller.input ""
|
|
end
|
|
|
|
controller.input = function(char)
|
|
prompt.input(char)
|
|
vim.schedule(function()
|
|
window.set_items(controller.items(prompt.text()))
|
|
end)
|
|
end
|
|
|
|
controller.search = function(value)
|
|
prompt.set(value)
|
|
vim.schedule(function()
|
|
window.set_items(controller.items(prompt.text()))
|
|
end)
|
|
end
|
|
|
|
controller.complete = function()
|
|
controller.checkpoint()
|
|
controller.destroy()
|
|
end
|
|
|
|
controller.checkpoint = function()
|
|
vim.api.nvim_set_current_win(window.previous)
|
|
controller.callback(window.get_current_selection())
|
|
vim.api.nvim_set_current_win(window.window)
|
|
end
|
|
|
|
controller.next = function()
|
|
window.index = window.index + 1
|
|
window.update()
|
|
end
|
|
|
|
controller.previous = function()
|
|
window.index = window.index - 1
|
|
window.update()
|
|
end
|
|
|
|
controller.destroy = function()
|
|
controller.items = nil
|
|
controller.callback = nil
|
|
|
|
window.destroy()
|
|
prompt.destroy()
|
|
end
|
|
|
|
return controller
|