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, "buftype", "acwrite")
|
||||||
vim.api.nvim_buf_set_option(bufnr, "bufhidden", "delete")
|
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(
|
vim.api.nvim_buf_set_keymap(
|
||||||
bufnr,
|
bufnr,
|
||||||
"n",
|
"n",
|
||||||
|
@ -56,7 +56,8 @@ local function read_data()
|
|||||||
write_data({})
|
write_data({})
|
||||||
end
|
end
|
||||||
|
|
||||||
local data = vim.json.decode(path:read())
|
local out_data = path:read()
|
||||||
|
local data = vim.json.decode(out_data)
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -52,7 +52,6 @@ function Harpoon:setup(partial_config)
|
|||||||
group = HarpoonGroup,
|
group = HarpoonGroup,
|
||||||
pattern = '*',
|
pattern = '*',
|
||||||
callback = function(ev)
|
callback = function(ev)
|
||||||
--[[
|
|
||||||
self:_for_each_list(function(list, config)
|
self:_for_each_list(function(list, config)
|
||||||
|
|
||||||
local fn = config[ev.event]
|
local fn = config[ev.event]
|
||||||
@ -64,7 +63,6 @@ function Harpoon:setup(partial_config)
|
|||||||
self:sync()
|
self:sync()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
--]]
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -143,12 +141,4 @@ function Harpoon:__debug_reset()
|
|||||||
require("plenary.reload").reload_module("harpoon2")
|
require("plenary.reload").reload_module("harpoon2")
|
||||||
end
|
end
|
||||||
|
|
||||||
local harpoon = Harpoon:new()
|
return 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
|
|
||||||
|
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 utils = require("harpoon2.test.utils")
|
||||||
local Data = require("harpoon2.data")
|
|
||||||
local harpoon = require("harpoon2")
|
local harpoon = require("harpoon2")
|
||||||
|
|
||||||
local eq = assert.are.same
|
local eq = assert.are.same
|
||||||
|
|
||||||
|
local be = utils.before_each(os.tmpname())
|
||||||
|
|
||||||
describe("harpoon", function()
|
describe("harpoon", function()
|
||||||
|
|
||||||
|
|
||||||
before_each(function()
|
before_each(function()
|
||||||
Data.set_data_path("/tmp/harpoon2.json")
|
be()
|
||||||
Data.__dangerously_clear_data()
|
|
||||||
require("plenary.reload").reload_module("harpoon2")
|
|
||||||
Data = require("harpoon2.data")
|
|
||||||
Data.set_data_path("/tmp/harpoon2.json")
|
|
||||||
harpoon = require("harpoon2")
|
harpoon = require("harpoon2")
|
||||||
utils.clean_files()
|
|
||||||
|
|
||||||
harpoon:setup({
|
|
||||||
settings = {
|
|
||||||
key = function()
|
|
||||||
return "testies"
|
|
||||||
end
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it("when we change buffers we update the row and column", function()
|
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}},
|
{value = file_name, context = {row = row + 1, col = col}},
|
||||||
}
|
}
|
||||||
|
|
||||||
eq(list.items, expected)
|
eq(expected, list.items)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@ -69,7 +55,8 @@ describe("harpoon", function()
|
|||||||
"qux"
|
"qux"
|
||||||
}, row, col)
|
}, row, col)
|
||||||
|
|
||||||
local list = harpoon:list():append()
|
local list = harpoon:list()
|
||||||
|
list:append()
|
||||||
harpoon:sync()
|
harpoon:sync()
|
||||||
|
|
||||||
eq(harpoon:dump(), {
|
eq(harpoon:dump(), {
|
||||||
|
@ -4,13 +4,21 @@ local eq = assert.are.same
|
|||||||
|
|
||||||
describe("harpoon", function()
|
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()
|
it("open the ui without any items in the list", function()
|
||||||
local harpoon = require("harpoon2")
|
local harpoon = require("harpoon2")
|
||||||
harpoon.ui:toggle_quick_menu(harpoon:list())
|
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)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
@ -4,22 +4,27 @@ local M = {}
|
|||||||
|
|
||||||
M.created_files = {}
|
M.created_files = {}
|
||||||
|
|
||||||
function M.before_each()
|
---@param name string
|
||||||
Data.set_data_path("/tmp/harpoon2.json")
|
function M.before_each(name)
|
||||||
Data.__dangerously_clear_data()
|
return function()
|
||||||
require("plenary.reload").reload_module("harpoon2")
|
Data.set_data_path(name)
|
||||||
Data = require("harpoon2.data")
|
Data.__dangerously_clear_data()
|
||||||
Data.set_data_path("/tmp/harpoon2.json")
|
|
||||||
local harpoon = require("harpoon2")
|
|
||||||
M.clean_files()
|
|
||||||
|
|
||||||
harpoon:setup({
|
require("plenary.reload").reload_module("harpoon2")
|
||||||
settings = {
|
Data = require("harpoon2.data")
|
||||||
key = function()
|
Data.set_data_path(name)
|
||||||
return "testies"
|
local harpoon = require("harpoon2")
|
||||||
end
|
|
||||||
}
|
M.clean_files()
|
||||||
})
|
|
||||||
|
harpoon:setup({
|
||||||
|
settings = {
|
||||||
|
key = function()
|
||||||
|
return "testies"
|
||||||
|
end
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.clean_files()
|
function M.clean_files()
|
||||||
|
@ -23,18 +23,25 @@ function HarpoonUI:new(settings)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function HarpoonUI:close_menu()
|
function HarpoonUI:close_menu()
|
||||||
print("CLOSING MENU")
|
if self.closing then
|
||||||
if self.win_id ~= nil and vim.api.nvim_win_is_valid(self.win_id) then
|
return
|
||||||
vim.api.nvim_win_close(self.win_id, true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self.closing = true
|
||||||
|
|
||||||
if self.bufnr ~= nil and vim.api.nvim_buf_is_valid(self.bufnr) then
|
if self.bufnr ~= nil and vim.api.nvim_buf_is_valid(self.bufnr) then
|
||||||
vim.api.nvim_buf_delete(self.bufnr, { force = true })
|
vim.api.nvim_buf_delete(self.bufnr, { force = true })
|
||||||
end
|
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.active_list = nil
|
||||||
self.win_id = nil
|
self.win_id = nil
|
||||||
self.bufnr = nil
|
self.bufnr = nil
|
||||||
|
|
||||||
|
self.closing = false
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return number,number
|
---@return number,number
|
||||||
@ -51,7 +58,7 @@ function HarpoonUI:_create_window()
|
|||||||
local height = 8
|
local height = 8
|
||||||
local borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }
|
local borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }
|
||||||
local bufnr = vim.api.nvim_create_buf(false, false)
|
local bufnr = vim.api.nvim_create_buf(false, false)
|
||||||
local win_id, _ = popup.create(bufnr, {
|
local _, popup_info = popup.create(bufnr, {
|
||||||
title = "Harpoon",
|
title = "Harpoon",
|
||||||
highlight = "HarpoonWindow",
|
highlight = "HarpoonWindow",
|
||||||
line = math.floor(((vim.o.lines - height) / 2) - 1),
|
line = math.floor(((vim.o.lines - height) / 2) - 1),
|
||||||
@ -60,6 +67,8 @@ function HarpoonUI:_create_window()
|
|||||||
minheight = height,
|
minheight = height,
|
||||||
borderchars = borderchars,
|
borderchars = borderchars,
|
||||||
})
|
})
|
||||||
|
local win_id = popup_info.win_id
|
||||||
|
|
||||||
Buffer.setup_autocmds_and_keymaps(bufnr)
|
Buffer.setup_autocmds_and_keymaps(bufnr)
|
||||||
|
|
||||||
self.win_id = win_id
|
self.win_id = win_id
|
||||||
@ -75,11 +84,10 @@ end
|
|||||||
|
|
||||||
local count = 0
|
local count = 0
|
||||||
|
|
||||||
---@param list HarpoonList
|
---@param list? HarpoonList
|
||||||
function HarpoonUI:toggle_quick_menu(list)
|
function HarpoonUI:toggle_quick_menu(list)
|
||||||
|
|
||||||
count = count + 1
|
count = count + 1
|
||||||
print("toggle?", self.win_id, self.bufnr, count)
|
|
||||||
|
|
||||||
if list == nil or self.win_id ~= nil then
|
if list == nil or self.win_id ~= nil then
|
||||||
self:close_menu()
|
self:close_menu()
|
||||||
@ -88,7 +96,6 @@ function HarpoonUI:toggle_quick_menu(list)
|
|||||||
|
|
||||||
local win_id, bufnr = self:_create_window()
|
local win_id, bufnr = self:_create_window()
|
||||||
|
|
||||||
print("_create_window_results", win_id, bufnr, count)
|
|
||||||
self.win_id = win_id
|
self.win_id = win_id
|
||||||
self.bufnr = bufnr
|
self.bufnr = bufnr
|
||||||
self.active_list = list
|
self.active_list = list
|
||||||
@ -98,14 +105,12 @@ function HarpoonUI:toggle_quick_menu(list)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function HarpoonUI:select_menu_item()
|
function HarpoonUI:select_menu_item()
|
||||||
error("select_menu_item...?")
|
|
||||||
local idx = vim.fn.line(".")
|
local idx = vim.fn.line(".")
|
||||||
self.active_list:select(idx)
|
self.active_list:select(idx)
|
||||||
self:close_menu()
|
self:close_menu()
|
||||||
end
|
end
|
||||||
|
|
||||||
function HarpoonUI:on_menu_save()
|
function HarpoonUI:on_menu_save()
|
||||||
error("saving...?")
|
|
||||||
local list = Buffer.get_contents(self.bufnr)
|
local list = Buffer.get_contents(self.bufnr)
|
||||||
self.active_list:resolve_displayed(list)
|
self.active_list:resolve_displayed(list)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user