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:
parent
75d1c0d171
commit
7577706545
2 changed files with 8 additions and 4 deletions
|
|
@ -37,7 +37,7 @@ controller.complete = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
controller.checkpoint = function()
|
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())
|
controller.callback(window.get_current_selection())
|
||||||
vim.api.nvim_set_current_win(window.window)
|
vim.api.nvim_set_current_win(window.window)
|
||||||
end
|
end
|
||||||
|
|
@ -52,6 +52,10 @@ controller.previous = function()
|
||||||
window.update()
|
window.update()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
controller.origin = function()
|
||||||
|
return vim.api.nvim_win_get_buf(window.origin)
|
||||||
|
end
|
||||||
|
|
||||||
controller.destroy = function()
|
controller.destroy = function()
|
||||||
controller.items = nil
|
controller.items = nil
|
||||||
controller.callback = nil
|
controller.callback = nil
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ end
|
||||||
local window = {}
|
local window = {}
|
||||||
|
|
||||||
window.index = 0
|
window.index = 0
|
||||||
window.previous = nil
|
window.origin = nil
|
||||||
window.window = nil
|
window.window = nil
|
||||||
window.buffer = nil
|
window.buffer = nil
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ window.initialize = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
window.make_buffer = function()
|
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"
|
vim.api.nvim_command "botright split new"
|
||||||
window.buffer = vim.api.nvim_win_get_buf(0)
|
window.buffer = vim.api.nvim_win_get_buf(0)
|
||||||
|
|
@ -135,7 +135,7 @@ window.destroy = function()
|
||||||
|
|
||||||
window.buffer = nil
|
window.buffer = nil
|
||||||
window.window = nil
|
window.window = nil
|
||||||
window.previous = nil
|
window.origin = nil
|
||||||
window.index = 0
|
window.index = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue