feat: Use vim.keymap.set for setting keymaps

This commit is contained in:
Simrat Grewal
2022-08-10 15:08:46 -07:00
parent d12af70950
commit 374b80010a
2 changed files with 17 additions and 12 deletions

View File

@@ -57,7 +57,7 @@ end
M._refresh = utils.debounce(__refresh, 100) M._refresh = utils.debounce(__refresh, 100)
function M._goto_location(change_focus) local function goto_location(change_focus)
local current_line = vim.api.nvim_win_get_cursor(M.view.winnr)[1] local current_line = vim.api.nvim_win_get_cursor(M.view.winnr)[1]
local node = M.state.flattened_outline_items[current_line] local node = M.state.flattened_outline_items[current_line]
vim.api.nvim_win_set_cursor(M.state.code_win, { node.line + 1, node.character }) vim.api.nvim_win_set_cursor(M.state.code_win, { node.line + 1, node.character })
@@ -114,21 +114,25 @@ local function setup_keymaps(bufnr)
utils.nmap(bufnr, ...) utils.nmap(bufnr, ...)
end end
-- goto_location of symbol and focus that window -- goto_location of symbol and focus that window
map(config.options.keymaps.goto_location, ":lua require('symbols-outline')._goto_location(true)<Cr>") map(config.options.keymaps.goto_location, function()
goto_location(true)
end)
-- goto_location of symbol but stay in outline -- goto_location of symbol but stay in outline
map(config.options.keymaps.focus_location, ":lua require('symbols-outline')._goto_location(false)<Cr>") map(config.options.keymaps.focus_location, function()
goto_location(false)
end)
-- hover symbol -- hover symbol
map(config.options.keymaps.hover_symbol, ":lua require('symbols-outline.hover').show_hover()<Cr>") map(config.options.keymaps.hover_symbol, require('symbols-outline.hover').show_hover)
-- preview symbol -- preview symbol
map(config.options.keymaps.toggle_preview, ":lua require('symbols-outline.preview').toggle()<Cr>") map(config.options.keymaps.toggle_preview, require('symbols-outline.preview').toggle)
-- rename symbol -- rename symbol
map(config.options.keymaps.rename_symbol, ":lua require('symbols-outline.rename').rename()<Cr>") map(config.options.keymaps.rename_symbol, require('symbols-outline.rename').rename)
-- code actions -- code actions
map(config.options.keymaps.code_actions, ":lua require('symbols-outline.code_action').show_code_actions()<Cr>") map(config.options.keymaps.code_actions, require('symbols-outline.code_action').show_code_actions)
-- show help -- show help
map(config.options.keymaps.show_help, ":lua require('symbols-outline.config').show_help()<Cr>") map(config.options.keymaps.show_help, require('symbols-outline.config').show_help)
-- close outline -- close outline
map(config.options.keymaps.close, ':bw!<Cr>') map(config.options.keymaps.close, M.view.close)
end end
local function handler(response) local function handler(response)

View File

@@ -2,14 +2,15 @@ local M = {}
---maps the table|string of keys to the action ---maps the table|string of keys to the action
---@param keys table|string ---@param keys table|string
---@param action string ---@param action function|string
function M.nmap(bufnr, keys, action) function M.nmap(bufnr, keys, action)
if type(keys) == 'string' then if type(keys) == 'string' then
keys = { keys } keys = { keys }
end end
for _, value in ipairs(keys) do
vim.api.nvim_buf_set_keymap(bufnr, 'n', value, action, { silent = true, noremap = true }) for _, lhs in ipairs(keys) do
vim.keymap.set('n', lhs, action, { silent = true, noremap = true, buffer = bufnr })
end end
end end