outline: Use vim.fn.win_gotoid to move between windows
Also keep track of the currently focused code window
This commit is contained in:
@@ -31,7 +31,8 @@ D.state = {
|
|||||||
outline_items = {},
|
outline_items = {},
|
||||||
linear_outline_items = {},
|
linear_outline_items = {},
|
||||||
outline_win = nil,
|
outline_win = nil,
|
||||||
outline_buf = nil
|
outline_buf = nil,
|
||||||
|
code_win = nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
local function wipe_state()
|
local function wipe_state()
|
||||||
@@ -48,7 +49,7 @@ end
|
|||||||
function D.goto_location()
|
function D.goto_location()
|
||||||
local current_line = vim.api.nvim_win_get_cursor(D.state.outline_win)[1]
|
local current_line = vim.api.nvim_win_get_cursor(D.state.outline_win)[1]
|
||||||
local node = D.state.linear_outline_items[current_line]
|
local node = D.state.linear_outline_items[current_line]
|
||||||
vim.cmd("wincmd p")
|
vim.fn.win_gotoid(D.state.code_win)
|
||||||
vim.fn.cursor(node.line + 1, node.character + 1)
|
vim.fn.cursor(node.line + 1, node.character + 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -151,6 +152,7 @@ function D._refresh()
|
|||||||
vim.lsp.buf_request(0, "textDocument/documentSymbol", getParams(),
|
vim.lsp.buf_request(0, "textDocument/documentSymbol", getParams(),
|
||||||
function(_, _, result)
|
function(_, _, result)
|
||||||
|
|
||||||
|
D.state.code_win = vim.api.nvim_get_current_win()
|
||||||
D.state.outline_items = parse(result)
|
D.state.outline_items = parse(result)
|
||||||
D.state.linear_outline_items = make_linear(parse(result))
|
D.state.linear_outline_items = make_linear(parse(result))
|
||||||
|
|
||||||
@@ -165,6 +167,8 @@ function D._refresh()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function handler(_, _, result)
|
local function handler(_, _, result)
|
||||||
|
D.state.code_win = vim.api.nvim_get_current_win()
|
||||||
|
|
||||||
D.state.outline_buf = vim.api.nvim_create_buf(false, true)
|
D.state.outline_buf = vim.api.nvim_create_buf(false, true)
|
||||||
vim.api.nvim_buf_attach(D.state.outline_buf, false,
|
vim.api.nvim_buf_attach(D.state.outline_buf, false,
|
||||||
{on_detach = function(_, _) wipe_state() end})
|
{on_detach = function(_, _) wipe_state() end})
|
||||||
|
|||||||
Reference in New Issue
Block a user