From 8edb1e005b7d2ad6085318680ad0557051bfb6bc Mon Sep 17 00:00:00 2001 From: simrat39 Date: Fri, 23 Apr 2021 15:06:10 -0700 Subject: [PATCH] feat: Add keymap to go to location without losing focus --- lua/symbols-outline.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lua/symbols-outline.lua b/lua/symbols-outline.lua index d041389..e9862d4 100644 --- a/lua/symbols-outline.lua +++ b/lua/symbols-outline.lua @@ -59,11 +59,12 @@ function M._refresh() end end -function M._goto_location() +function M._goto_location(change_focus) local current_line = vim.api.nvim_win_get_cursor(M.state.outline_win)[1] local node = M.state.flattened_outline_items[current_line] - vim.fn.win_gotoid(M.state.code_win) - vim.fn.cursor(node.line + 1, node.character + 1) + vim.api.nvim_win_set_cursor(M.state.code_win, {node.line + 1, + node.character}) + if change_focus then vim.fn.win_gotoid(M.state.code_win) end end function M._highlight_current_item() @@ -120,9 +121,13 @@ function M._prevent_buffer_override() end local function setup_keymaps(bufnr) - -- goto_location of symbol + -- goto_location of symbol and focus that window vim.api.nvim_buf_set_keymap(bufnr, "n", "", - ":lua require('symbols-outline')._goto_location()", + ":lua require('symbols-outline')._goto_location(true)", + {}) + -- goto_location of symbol but stay in outline + vim.api.nvim_buf_set_keymap(bufnr, "n", "o", + ":lua require('symbols-outline')._goto_location(false)", {}) -- hover symbol vim.api.nvim_buf_set_keymap(bufnr, "n", "", @@ -133,7 +138,7 @@ local function setup_keymaps(bufnr) ":lua require('symbols-outline.rename').rename()", {}) -- close outline when escape is pressed - vim.api.nvim_buf_set_keymap(bufnr, "n", "", ":bw!", {}) + vim.api.nvim_buf_set_keymap(bufnr, "n", "", ":bw!",{}) end ----------------------------