mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 10:00:29 +00:00
feat: toggling menu now works!
This commit is contained in:
parent
5d7ee0d894
commit
b22cb4a873
@ -42,16 +42,6 @@ function M.setup_autocmds_and_keymaps(bufnr)
|
||||
vim.api.nvim_buf_set_option(bufnr, "buftype", "acwrite")
|
||||
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "delete")
|
||||
|
||||
--[[
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
bufnr,
|
||||
"n",
|
||||
"z",
|
||||
"<Cmd>lua print('WTF')<CR>",
|
||||
{ silent = true }
|
||||
)
|
||||
--]]
|
||||
|
||||
vim.api.nvim_buf_set_keymap(
|
||||
bufnr,
|
||||
"n",
|
||||
|
@ -56,7 +56,8 @@ local function read_data()
|
||||
write_data({})
|
||||
end
|
||||
|
||||
local data = vim.json.decode(path:read())
|
||||
local out_data = path:read()
|
||||
local data = vim.json.decode(out_data)
|
||||
return data
|
||||
end
|
||||
|
||||
|
@ -52,7 +52,6 @@ function Harpoon:setup(partial_config)
|
||||
group = HarpoonGroup,
|
||||
pattern = '*',
|
||||
callback = function(ev)
|
||||
--[[
|
||||
self:_for_each_list(function(list, config)
|
||||
|
||||
local fn = config[ev.event]
|
||||
@ -64,7 +63,6 @@ function Harpoon:setup(partial_config)
|
||||
self:sync()
|
||||
end
|
||||
end)
|
||||
--]]
|
||||
end,
|
||||
})
|
||||
|
||||
@ -143,12 +141,4 @@ function Harpoon:__debug_reset()
|
||||
require("plenary.reload").reload_module("harpoon2")
|
||||
end
|
||||
|
||||
local harpoon = Harpoon:new()
|
||||
HARPOON_DEBUG_VAR = HARPOON_DEBUG_VAR or 0
|
||||
if HARPOON_DEBUG_VAR == 0 then
|
||||
harpoon.ui:toggle_quick_menu(harpoon:list())
|
||||
HARPOON_DEBUG_VAR = 1
|
||||
end
|
||||
-- leave this undone, i sometimes use this for debugging
|
||||
|
||||
return harpoon
|
||||
return Harpoon:new()
|
||||
|
6
lua/harpoon2/scratch/toggle.lua
Normal file
6
lua/harpoon2/scratch/toggle.lua
Normal file
@ -0,0 +1,6 @@
|
||||
|
||||
local harpoon = require("harpoon2")
|
||||
|
||||
harpoon.ui:toggle_quick_menu(harpoon:list())
|
||||
|
||||
|
@ -1,29 +1,15 @@
|
||||
local utils = require("harpoon2.test.utils")
|
||||
local Data = require("harpoon2.data")
|
||||
local harpoon = require("harpoon2")
|
||||
|
||||
local eq = assert.are.same
|
||||
|
||||
local be = utils.before_each(os.tmpname())
|
||||
|
||||
describe("harpoon", function()
|
||||
|
||||
|
||||
before_each(function()
|
||||
Data.set_data_path("/tmp/harpoon2.json")
|
||||
Data.__dangerously_clear_data()
|
||||
require("plenary.reload").reload_module("harpoon2")
|
||||
Data = require("harpoon2.data")
|
||||
Data.set_data_path("/tmp/harpoon2.json")
|
||||
be()
|
||||
harpoon = require("harpoon2")
|
||||
utils.clean_files()
|
||||
|
||||
harpoon:setup({
|
||||
settings = {
|
||||
key = function()
|
||||
return "testies"
|
||||
end
|
||||
}
|
||||
})
|
||||
|
||||
end)
|
||||
|
||||
it("when we change buffers we update the row and column", function()
|
||||
@ -53,7 +39,7 @@ describe("harpoon", function()
|
||||
{value = file_name, context = {row = row + 1, col = col}},
|
||||
}
|
||||
|
||||
eq(list.items, expected)
|
||||
eq(expected, list.items)
|
||||
|
||||
end)
|
||||
|
||||
@ -69,7 +55,8 @@ describe("harpoon", function()
|
||||
"qux"
|
||||
}, row, col)
|
||||
|
||||
local list = harpoon:list():append()
|
||||
local list = harpoon:list()
|
||||
list:append()
|
||||
harpoon:sync()
|
||||
|
||||
eq(harpoon:dump(), {
|
||||
|
@ -4,13 +4,21 @@ local eq = assert.are.same
|
||||
|
||||
describe("harpoon", function()
|
||||
|
||||
before_each(utils.before_each)
|
||||
before_each(utils.before_each(os.tmpname()))
|
||||
|
||||
it("open the ui without any items in the list", function()
|
||||
local harpoon = require("harpoon2")
|
||||
harpoon.ui:toggle_quick_menu(harpoon:list())
|
||||
|
||||
-- no test, just wanted it to run without error'ing
|
||||
local bufnr = harpoon.ui.bufnr
|
||||
local win_id = harpoon.ui.win_id
|
||||
|
||||
harpoon.ui:toggle_quick_menu()
|
||||
|
||||
eq(vim.api.nvim_buf_is_valid(bufnr), false)
|
||||
eq(vim.api.nvim_win_is_valid(win_id), false)
|
||||
eq(harpoon.ui.bufnr, nil)
|
||||
eq(harpoon.ui.win_id, nil)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
@ -4,13 +4,17 @@ local M = {}
|
||||
|
||||
M.created_files = {}
|
||||
|
||||
function M.before_each()
|
||||
Data.set_data_path("/tmp/harpoon2.json")
|
||||
---@param name string
|
||||
function M.before_each(name)
|
||||
return function()
|
||||
Data.set_data_path(name)
|
||||
Data.__dangerously_clear_data()
|
||||
|
||||
require("plenary.reload").reload_module("harpoon2")
|
||||
Data = require("harpoon2.data")
|
||||
Data.set_data_path("/tmp/harpoon2.json")
|
||||
Data.set_data_path(name)
|
||||
local harpoon = require("harpoon2")
|
||||
|
||||
M.clean_files()
|
||||
|
||||
harpoon:setup({
|
||||
@ -20,6 +24,7 @@ function M.before_each()
|
||||
end
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function M.clean_files()
|
||||
|
@ -23,18 +23,25 @@ function HarpoonUI:new(settings)
|
||||
end
|
||||
|
||||
function HarpoonUI:close_menu()
|
||||
print("CLOSING MENU")
|
||||
if self.win_id ~= nil and vim.api.nvim_win_is_valid(self.win_id) then
|
||||
vim.api.nvim_win_close(self.win_id, true)
|
||||
if self.closing then
|
||||
return
|
||||
end
|
||||
|
||||
self.closing = true
|
||||
|
||||
if self.bufnr ~= nil and vim.api.nvim_buf_is_valid(self.bufnr) then
|
||||
vim.api.nvim_buf_delete(self.bufnr, { force = true })
|
||||
end
|
||||
|
||||
if self.win_id ~= nil and vim.api.nvim_win_is_valid(self.win_id) then
|
||||
vim.api.nvim_win_close(self.win_id, true)
|
||||
end
|
||||
|
||||
self.active_list = nil
|
||||
self.win_id = nil
|
||||
self.bufnr = nil
|
||||
|
||||
self.closing = false
|
||||
end
|
||||
|
||||
---@return number,number
|
||||
@ -51,7 +58,7 @@ function HarpoonUI:_create_window()
|
||||
local height = 8
|
||||
local borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }
|
||||
local bufnr = vim.api.nvim_create_buf(false, false)
|
||||
local win_id, _ = popup.create(bufnr, {
|
||||
local _, popup_info = popup.create(bufnr, {
|
||||
title = "Harpoon",
|
||||
highlight = "HarpoonWindow",
|
||||
line = math.floor(((vim.o.lines - height) / 2) - 1),
|
||||
@ -60,6 +67,8 @@ function HarpoonUI:_create_window()
|
||||
minheight = height,
|
||||
borderchars = borderchars,
|
||||
})
|
||||
local win_id = popup_info.win_id
|
||||
|
||||
Buffer.setup_autocmds_and_keymaps(bufnr)
|
||||
|
||||
self.win_id = win_id
|
||||
@ -75,11 +84,10 @@ end
|
||||
|
||||
local count = 0
|
||||
|
||||
---@param list HarpoonList
|
||||
---@param list? HarpoonList
|
||||
function HarpoonUI:toggle_quick_menu(list)
|
||||
|
||||
count = count + 1
|
||||
print("toggle?", self.win_id, self.bufnr, count)
|
||||
|
||||
if list == nil or self.win_id ~= nil then
|
||||
self:close_menu()
|
||||
@ -88,7 +96,6 @@ function HarpoonUI:toggle_quick_menu(list)
|
||||
|
||||
local win_id, bufnr = self:_create_window()
|
||||
|
||||
print("_create_window_results", win_id, bufnr, count)
|
||||
self.win_id = win_id
|
||||
self.bufnr = bufnr
|
||||
self.active_list = list
|
||||
@ -98,14 +105,12 @@ function HarpoonUI:toggle_quick_menu(list)
|
||||
end
|
||||
|
||||
function HarpoonUI:select_menu_item()
|
||||
error("select_menu_item...?")
|
||||
local idx = vim.fn.line(".")
|
||||
self.active_list:select(idx)
|
||||
self:close_menu()
|
||||
end
|
||||
|
||||
function HarpoonUI:on_menu_save()
|
||||
error("saving...?")
|
||||
local list = Buffer.get_contents(self.bufnr)
|
||||
self.active_list:resolve_displayed(list)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user