refactor: implement the origin api

This will allow you to get the buffer the user was on when they invoked
an ivy command. This buffer is called the `origin` and you can access it
with `vim.ivy.origin()`.
This commit is contained in:
Ade Attwood 2022-07-23 20:17:31 +01:00
parent 75d1c0d171
commit 7577706545
2 changed files with 8 additions and 4 deletions

View file

@ -37,7 +37,7 @@ controller.complete = function()
end
controller.checkpoint = function()
vim.api.nvim_set_current_win(window.previous)
vim.api.nvim_set_current_win(window.origin)
controller.callback(window.get_current_selection())
vim.api.nvim_set_current_win(window.window)
end
@ -52,6 +52,10 @@ controller.previous = function()
window.update()
end
controller.origin = function()
return vim.api.nvim_win_get_buf(window.origin)
end
controller.destroy = function()
controller.items = nil
controller.callback = nil

View file

@ -38,7 +38,7 @@ end
local window = {}
window.index = 0
window.previous = nil
window.origin = nil
window.window = nil
window.buffer = nil
@ -47,7 +47,7 @@ window.initialize = function()
end
window.make_buffer = function()
window.previous = vim.api.nvim_get_current_win()
window.origin = vim.api.nvim_get_current_win()
vim.api.nvim_command "botright split new"
window.buffer = vim.api.nvim_win_get_buf(0)
@ -135,7 +135,7 @@ window.destroy = function()
window.buffer = nil
window.window = nil
window.previous = nil
window.origin = nil
window.index = 0
end