fix: navigation

This commit is contained in:
mpaulson 2023-12-05 07:27:16 -07:00
parent ec03b3cc4b
commit e2e582e776
2 changed files with 23 additions and 67 deletions

View File

@ -16,6 +16,19 @@ local function get_harpoon_menu_name()
return HARPOON_MENU .. harpoon_menu_id
end
function M.run_select_command()
local harpoon = require("harpoon")
harpoon.logger:log('select by keymap \'<CR>\'')
harpoon.ui:select_menu_item()
end
function M.run_toggle_command(key)
local harpoon = require("harpoon")
harpoon.logger:log('toggle by keymap \'' .. key .. '\'')
harpoon.ui:select_menu_item()
end
---TODO: I don't know how to do what i want to do, but i want to be able to
---make this so we use callbacks for these buffer actions instead of using
---strings back into the ui. it feels gross and it puts odd coupling
@ -45,21 +58,21 @@ function M.setup_autocmds_and_keymaps(bufnr)
bufnr,
"n",
"q",
"<Cmd>lua require('harpoon').logger:log('toggle by keymap \'q\''); require('harpoon').ui:toggle_quick_menu()<CR>",
"<Cmd>lua require('harpoon.buffer').run_toggle_command('q')<CR>",
{ silent = true }
)
vim.api.nvim_buf_set_keymap(
bufnr,
"n",
"<ESC>",
"<Cmd>lua require('harpoon').logger:log('toggle by keymap \'<Esc>\''); require('harpoon').ui:toggle_quick_menu()<CR>",
"<Cmd>lua require('harpoon.buffer').run_toggle_command('<ESC>')<CR>",
{ silent = true }
)
vim.api.nvim_buf_set_keymap(
bufnr,
"n",
"<CR>",
"<Cmd>lua require('harpoon').logger:log('select by keymap \'<CR>\''); require('harpoon').ui:select_menu_item()<CR>",
"<Cmd>lua require('harpoon.buffer').run_select_command()<CR>",
{}
)

View File

@ -11,6 +11,12 @@ local DEFAULT_WINDOW_WIDTH = 69 -- nice
---@field active_list HarpoonList
local HarpoonUI = {}
---@param list HarpoonList
---@return string
local function list_name(list)
return list and list.name or "nil"
end
HarpoonUI.__index = HarpoonUI
---@param settings HarpoonSettings
@ -25,21 +31,13 @@ function HarpoonUI:new(settings)
}, self)
end
local function get_name(list)
if list ~= nil then
return list.name
end
return "(list nil)"
end
function HarpoonUI:close_menu()
if self.closing then
return
end
self.closing = true
Logger:log("ui#close_menu name: ", get_name(self.active_list), "win and bufnr", {
Logger:log("ui#close_menu name: ", list_name(self.active_list), "win and bufnr", {
win = self.win_id,
bufnr = self.bufnr
})
@ -152,59 +150,4 @@ function HarpoonUI:configure(settings)
self.settings = settings
end
--[[
function M.location_window(options)
local default_options = {
relative = "editor",
style = "minimal",
width = 30,
height = 15,
row = 2,
col = 2,
}
options = vim.tbl_extend("keep", options, default_options)
local bufnr = options.bufnr or vim.api.nvim_create_buf(false, true)
local win_id = vim.api.nvim_open_win(bufnr, true, options)
return {
bufnr = bufnr,
win_id = win_id,
}
end
-- TODO: What is this used for?
function M.notification(text)
local win_stats = vim.api.nvim_list_uis()[1]
local win_width = win_stats.width
local prev_win = vim.api.nvim_get_current_win()
local info = M.location_window({
width = 20,
height = 2,
row = 1,
col = win_width - 21,
})
vim.api.nvim_buf_set_lines(
info.bufnr,
0,
5,
false,
{ "!!! Notification", text }
)
vim.api.nvim_set_current_win(prev_win)
return {
bufnr = info.bufnr,
win_id = info.win_id,
}
end
function M.close_notification(bufnr)
vim.api.nvim_buf_delete(bufnr)
end
--]]
return HarpoonUI