mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
feat: holed ui lists even with bonus whitespace
This commit is contained in:
parent
0d959f34c0
commit
77d52b2a88
@ -89,9 +89,7 @@ function M.get_contents(bufnr)
|
|||||||
local indices = {}
|
local indices = {}
|
||||||
|
|
||||||
for _, line in pairs(lines) do
|
for _, line in pairs(lines) do
|
||||||
if not utils.is_white_space(line) then
|
table.insert(indices, line)
|
||||||
table.insert(indices, line)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return indices
|
return indices
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
local Logger = require("harpoon.logger")
|
local Logger = require("harpoon.logger")
|
||||||
|
local utils = require("harpoon.utils")
|
||||||
local Extensions = require("harpoon.extensions")
|
local Extensions = require("harpoon.extensions")
|
||||||
|
|
||||||
local function guess_length(arr)
|
local function guess_length(arr)
|
||||||
@ -252,7 +253,7 @@ function HarpoonList:resolve_displayed(displayed, length)
|
|||||||
for i = 1, length do
|
for i = 1, length do
|
||||||
local v = displayed[i]
|
local v = displayed[i]
|
||||||
local index = index_of(list_displayed, self._length, v)
|
local index = index_of(list_displayed, self._length, v)
|
||||||
if v == "" then
|
if utils.is_white_space(v) then
|
||||||
new_list[i] = nil
|
new_list[i] = nil
|
||||||
elseif index == -1 then
|
elseif index == -1 then
|
||||||
new_list[i] = self.config.create_list_item(self.config, v)
|
new_list[i] = self.config.create_list_item(self.config, v)
|
||||||
|
@ -81,6 +81,35 @@ describe("harpoon", function()
|
|||||||
eq(created_files, list:display())
|
eq(created_files, list:display())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("ui with replace_at", function()
|
||||||
|
local one_f = os.tmpname()
|
||||||
|
local one = utils.create_file(one_f, { "one", })
|
||||||
|
local three_f = os.tmpname()
|
||||||
|
local three = utils.create_file(three_f, { "three", })
|
||||||
|
local context = { row = 1, col = 0 }
|
||||||
|
|
||||||
|
eq(0, harpoon:list():length())
|
||||||
|
vim.api.nvim_set_current_buf(three)
|
||||||
|
|
||||||
|
harpoon:list():replace_at(3)
|
||||||
|
eq(3, harpoon:list():length())
|
||||||
|
|
||||||
|
vim.api.nvim_set_current_buf(one)
|
||||||
|
harpoon:list():replace_at(1)
|
||||||
|
eq(3, harpoon:list():length())
|
||||||
|
|
||||||
|
harpoon.ui:toggle_quick_menu(harpoon:list())
|
||||||
|
|
||||||
|
key("<CR>")
|
||||||
|
|
||||||
|
eq(3, harpoon:list():length())
|
||||||
|
eq({
|
||||||
|
{ value = one_f, context = context },
|
||||||
|
nil,
|
||||||
|
{ value = three_f, context = context },
|
||||||
|
}, harpoon:list().items)
|
||||||
|
end)
|
||||||
|
|
||||||
it("using :q to leave harpoon should quit everything", function()
|
it("using :q to leave harpoon should quit everything", function()
|
||||||
harpoon.ui:toggle_quick_menu(harpoon:list())
|
harpoon.ui:toggle_quick_menu(harpoon:list())
|
||||||
|
|
||||||
|
@ -160,14 +160,19 @@ function HarpoonUI:toggle_quick_menu(list, opts)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function HarpoonUI:_get_processed_ui_contents()
|
||||||
|
local list = Buffer.get_contents(self.bufnr)
|
||||||
|
local length = #list
|
||||||
|
return list, length
|
||||||
|
end
|
||||||
|
|
||||||
---@param options? any
|
---@param options? any
|
||||||
function HarpoonUI:select_menu_item(options)
|
function HarpoonUI:select_menu_item(options)
|
||||||
local idx = vim.fn.line(".")
|
local idx = vim.fn.line(".")
|
||||||
|
|
||||||
-- must first save any updates potentially made to the list before
|
-- must first save any updates potentially made to the list before
|
||||||
-- navigating
|
-- navigating
|
||||||
local list = Buffer.get_contents(self.bufnr)
|
local list, length = self:_get_processed_ui_contents()
|
||||||
local length = #list
|
|
||||||
self.active_list:resolve_displayed(list, length)
|
self.active_list:resolve_displayed(list, length)
|
||||||
|
|
||||||
Logger:log(
|
Logger:log(
|
||||||
@ -185,13 +190,7 @@ function HarpoonUI:select_menu_item(options)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function HarpoonUI:save()
|
function HarpoonUI:save()
|
||||||
local list = Buffer.get_contents(self.bufnr)
|
local list, length = self:_get_processed_ui_contents()
|
||||||
local length = #list
|
|
||||||
for i, v in ipairs(list) do
|
|
||||||
if v == "" then
|
|
||||||
list[i] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Logger:log("ui#save", list)
|
Logger:log("ui#save", list)
|
||||||
self.active_list:resolve_displayed(list, length)
|
self.active_list:resolve_displayed(list, length)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user