mirror of
https://github.com/ThePrimeagen/harpoon.git
synced 2025-07-14 01:50:27 +00:00
refactor(ui): use 'number' option in quick_menu like in cmd-ui
This commit is contained in:
parent
22b2650315
commit
f227419697
@ -1,5 +1,6 @@
|
|||||||
local harpoon = require("harpoon")
|
local harpoon = require("harpoon")
|
||||||
local popup = require("plenary.popup")
|
local popup = require("plenary.popup")
|
||||||
|
local utils = require("harpoon.utils")
|
||||||
local log = require("harpoon.dev").log
|
local log = require("harpoon.dev").log
|
||||||
local term = require("harpoon.term")
|
local term = require("harpoon.term")
|
||||||
|
|
||||||
@ -53,17 +54,13 @@ local function create_window()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local function is_white_space(str)
|
|
||||||
return str:gsub("%s", "") == ""
|
|
||||||
end
|
|
||||||
|
|
||||||
local function get_menu_items()
|
local function get_menu_items()
|
||||||
log.trace("_get_menu_items()")
|
log.trace("_get_menu_items()")
|
||||||
local lines = vim.api.nvim_buf_get_lines(Harpoon_cmd_bufh, 0, -1, true)
|
local lines = vim.api.nvim_buf_get_lines(Harpoon_cmd_bufh, 0, -1, true)
|
||||||
local indices = {}
|
local indices = {}
|
||||||
|
|
||||||
for _, line in pairs(lines) do
|
for _, line in pairs(lines) do
|
||||||
if not is_white_space(line) then
|
if not utils.is_white_space(line) then
|
||||||
table.insert(indices, line)
|
table.insert(indices, line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
local harpoon = require("harpoon")
|
local harpoon = require("harpoon")
|
||||||
local popup = require("plenary.popup")
|
local popup = require("plenary.popup")
|
||||||
local Marked = require("harpoon.mark")
|
local Marked = require("harpoon.mark")
|
||||||
|
local utils = require("harpoon.utils")
|
||||||
local log = require("harpoon.dev").log
|
local log = require("harpoon.dev").log
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
@ -60,12 +61,9 @@ local function get_menu_items()
|
|||||||
local lines = vim.api.nvim_buf_get_lines(Harpoon_bufh, 0, -1, true)
|
local lines = vim.api.nvim_buf_get_lines(Harpoon_bufh, 0, -1, true)
|
||||||
local indices = {}
|
local indices = {}
|
||||||
|
|
||||||
for idx = 1, #lines do
|
for _, line in pairs(lines) do
|
||||||
local space_location = string.find(lines[idx], " ")
|
if not utils.is_white_space(line) then
|
||||||
log.debug("_get_menu_items():", idx, space_location)
|
table.insert(indices, line)
|
||||||
|
|
||||||
if space_location ~= nil then
|
|
||||||
table.insert(indices, string.sub(lines[idx], space_location + 1))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -91,9 +89,10 @@ M.toggle_quick_menu = function()
|
|||||||
if file == "" then
|
if file == "" then
|
||||||
file = "(empty)"
|
file = "(empty)"
|
||||||
end
|
end
|
||||||
contents[idx] = string.format("%d %s", idx, file)
|
contents[idx] = string.format("%s", file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_win_set_option(Harpoon_win_id, "number", true)
|
||||||
vim.api.nvim_buf_set_name(Harpoon_bufh, "harpoon-menu")
|
vim.api.nvim_buf_set_name(Harpoon_bufh, "harpoon-menu")
|
||||||
vim.api.nvim_buf_set_lines(Harpoon_bufh, 0, #contents, false, contents)
|
vim.api.nvim_buf_set_lines(Harpoon_bufh, 0, #contents, false, contents)
|
||||||
vim.api.nvim_buf_set_option(Harpoon_bufh, "filetype", "harpoon")
|
vim.api.nvim_buf_set_option(Harpoon_bufh, "filetype", "harpoon")
|
||||||
|
@ -6,6 +6,9 @@ local M = {
|
|||||||
normalize_path = function(item)
|
normalize_path = function(item)
|
||||||
return Path:new(item):make_relative(vim.loop.cwd())
|
return Path:new(item):make_relative(vim.loop.cwd())
|
||||||
end,
|
end,
|
||||||
|
is_white_space = function(str)
|
||||||
|
return str:gsub("%s", "") == ""
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
Loading…
x
Reference in New Issue
Block a user