mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-13 17:40:25 +00:00
Merge pull request #78 from ThePrimeagen/nav-fix
fix(ui): Navigation with enter on menu
This commit is contained in:
commit
fae9f7d14b
@ -1,4 +1,4 @@
|
||||
column_width = 120
|
||||
column_width = 80
|
||||
line_endings = "Unix"
|
||||
indent_type = "Spaces"
|
||||
indent_width = 4
|
||||
|
@ -59,7 +59,10 @@ local function ensure_correct_config(config)
|
||||
log.trace("_ensure_correct_config()")
|
||||
local projects = config.projects
|
||||
if projects[vim.loop.cwd()] == nil then
|
||||
log.debug("ensure_correct_config(): No config found for:", vim.loop.cwd())
|
||||
log.debug(
|
||||
"ensure_correct_config(): No config found for:",
|
||||
vim.loop.cwd()
|
||||
)
|
||||
projects[vim.loop.cwd()] = {
|
||||
mark = {
|
||||
marks = {},
|
||||
@ -77,7 +80,10 @@ local function ensure_correct_config(config)
|
||||
end
|
||||
|
||||
if proj.term == nil then
|
||||
log.debug("ensure_correct_config(): No terminal commands found for", vim.loop.cwd())
|
||||
log.debug(
|
||||
"ensure_correct_config(): No terminal commands found for",
|
||||
vim.loop.cwd()
|
||||
)
|
||||
proj.term = { cmds = {} }
|
||||
end
|
||||
|
||||
|
@ -21,7 +21,10 @@ local function emit_changed()
|
||||
end
|
||||
|
||||
for idx, cb in pairs(callbacks["changed"]) do
|
||||
log.trace(string.format("_emit_changed(): Running callback #%d for 'changed'", idx))
|
||||
log.trace(string.format(
|
||||
"_emit_changed(): Running callback #%d for 'changed'",
|
||||
idx
|
||||
))
|
||||
cb()
|
||||
end
|
||||
end
|
||||
@ -208,7 +211,11 @@ M.store_offset = function()
|
||||
end
|
||||
|
||||
local cursor_pos = vim.fn.getcurpos()
|
||||
log.debug(string.format("store_offset(): Stored row: %d, col: %d", cursor_pos[2], cursor_pos[3]))
|
||||
log.debug(string.format(
|
||||
"store_offset(): Stored row: %d, col: %d",
|
||||
cursor_pos[2],
|
||||
cursor_pos[3]
|
||||
))
|
||||
harpoon.get_mark_config().marks[idx].row = cursor_pos[2]
|
||||
harpoon.get_mark_config().marks[idx].col = cursor_pos[3]
|
||||
end)
|
||||
|
@ -27,22 +27,6 @@ local function create_terminal()
|
||||
return buf_id, term_id
|
||||
end
|
||||
|
||||
M.getCmd = function(idx)
|
||||
log.trace("getCmd()")
|
||||
local cmd
|
||||
if type(idx) == "number" then
|
||||
cmd = harpoon.get_term_config().cmds[idx]
|
||||
else
|
||||
log.error("getCmd(): Index is expected to be a number.")
|
||||
end
|
||||
|
||||
if cmd then
|
||||
return cmd
|
||||
else
|
||||
error("Command does not exist for that id.")
|
||||
end
|
||||
end
|
||||
|
||||
local function find_terminal(idx)
|
||||
log.trace("_find_terminal(): Terminal:", idx)
|
||||
local term_handle = terminals[idx]
|
||||
|
@ -8,12 +8,29 @@ local M = {}
|
||||
Harpoon_win_id = nil
|
||||
Harpoon_bufh = nil
|
||||
|
||||
-- We save before we close because we use the state of the buffer as the list
|
||||
-- of items.
|
||||
local function close_menu(force_save)
|
||||
force_save = force_save or false
|
||||
local global_config = harpoon.get_global_settings()
|
||||
|
||||
if global_config.save_on_toggle or force_save then
|
||||
require("harpoon.ui").on_menu_save()
|
||||
end
|
||||
|
||||
vim.api.nvim_win_close(Harpoon_win_id, true)
|
||||
|
||||
Harpoon_win_id = nil
|
||||
Harpoon_bufh = nil
|
||||
end
|
||||
|
||||
local function create_window()
|
||||
log.trace("_create_window()")
|
||||
local config = harpoon.get_menu_config()
|
||||
local width = config.width or 60
|
||||
local height = config.height or 10
|
||||
local borderchars = config.borderchars or { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }
|
||||
local borderchars = config.borderchars
|
||||
or { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }
|
||||
local bufnr = vim.api.nvim_create_buf(false, false)
|
||||
|
||||
local Harpoon_win_id, win = popup.create(bufnr, {
|
||||
@ -26,7 +43,11 @@ local function create_window()
|
||||
borderchars = borderchars,
|
||||
})
|
||||
|
||||
vim.api.nvim_win_set_option(win.border.win_id, "winhl", "Normal:HarpoonBorder")
|
||||
vim.api.nvim_win_set_option(
|
||||
win.border.win_id,
|
||||
"winhl",
|
||||
"Normal:HarpoonBorder"
|
||||
)
|
||||
|
||||
return {
|
||||
bufnr = bufnr,
|
||||
@ -54,17 +75,7 @@ end
|
||||
M.toggle_quick_menu = function()
|
||||
log.trace("toggle_quick_menu()")
|
||||
if Harpoon_win_id ~= nil and vim.api.nvim_win_is_valid(Harpoon_win_id) then
|
||||
local global_config = harpoon.get_global_settings()
|
||||
|
||||
if global_config.save_on_toggle then
|
||||
require("harpoon.ui").on_menu_save()
|
||||
end
|
||||
|
||||
vim.api.nvim_win_close(Harpoon_win_id, true)
|
||||
|
||||
Harpoon_win_id = nil
|
||||
Harpoon_bufh = nil
|
||||
|
||||
close_menu()
|
||||
return
|
||||
end
|
||||
|
||||
@ -87,13 +98,26 @@ M.toggle_quick_menu = function()
|
||||
vim.api.nvim_buf_set_option(Harpoon_bufh, "filetype", "harpoon")
|
||||
vim.api.nvim_buf_set_option(Harpoon_bufh, "buftype", "acwrite")
|
||||
vim.api.nvim_buf_set_option(Harpoon_bufh, "bufhidden", "delete")
|
||||
vim.api.nvim_buf_set_keymap(Harpoon_bufh, "n", "<CR>", ":lua require('harpoon.ui').on_norm_enter()<CR>", {})
|
||||
vim.cmd(string.format("autocmd BufWriteCmd <buffer=%s> :lua require('harpoon.ui').on_menu_save()", Harpoon_bufh))
|
||||
vim.cmd(string.format("autocmd BufModifiedSet <buffer=%s> set nomodified", Harpoon_bufh))
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
Harpoon_bufh,
|
||||
"n",
|
||||
"<CR>",
|
||||
":lua require('harpoon.ui').select_menu_item()<CR>",
|
||||
{}
|
||||
)
|
||||
vim.cmd(string.format(
|
||||
"autocmd BufWriteCmd <buffer=%s> :lua require('harpoon.ui').on_menu_save()",
|
||||
Harpoon_bufh
|
||||
))
|
||||
vim.cmd(string.format(
|
||||
"autocmd BufModifiedSet <buffer=%s> set nomodified",
|
||||
Harpoon_bufh
|
||||
))
|
||||
end
|
||||
|
||||
M.on_norm_enter = function()
|
||||
local idx = vim.fn.line('.')
|
||||
M.select_menu_item = function()
|
||||
local idx = vim.fn.line(".")
|
||||
close_menu(true)
|
||||
M.nav_file(idx)
|
||||
end
|
||||
|
||||
@ -117,7 +141,11 @@ M.nav_file = function(id)
|
||||
vim.api.nvim_set_current_buf(buf_id)
|
||||
if set_row and mark.row and mark.col then
|
||||
vim.cmd(string.format(":call cursor(%d, %d)", mark.row, mark.col))
|
||||
log.debug(string.format("nav_file(): Setting cursor to row: %d, col: %d", mark.row, mark.col))
|
||||
log.debug(string.format(
|
||||
"nav_file(): Setting cursor to row: %d, col: %d",
|
||||
mark.row,
|
||||
mark.col
|
||||
))
|
||||
end
|
||||
end
|
||||
|
||||
@ -154,7 +182,13 @@ function M.notification(text)
|
||||
col = win_width - 21,
|
||||
})
|
||||
|
||||
vim.api.nvim_buf_set_lines(info.bufnr, 0, 5, false, { "!!! Notification", text })
|
||||
vim.api.nvim_buf_set_lines(
|
||||
info.bufnr,
|
||||
0,
|
||||
5,
|
||||
false,
|
||||
{ "!!! Notification", text }
|
||||
)
|
||||
vim.api.nvim_set_current_win(prev_win)
|
||||
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user