BREAKING,feat: Customizable guide markers

See readme
This commit is contained in:
hedy
2023-11-02 17:46:27 +08:00
parent 841825b747
commit a87f73c3b2
5 changed files with 39 additions and 24 deletions

View File

@@ -6,7 +6,15 @@ M.defaults = {
position = 'right',
width = 25,
highlight_hovered_item = true,
show_guides = true,
guides = {
enabled = true,
markers = {
bottom = '',
middle = '',
vertical = '',
horizontal = '',
},
},
border = 'single',
relative_width = true,
auto_close = false,

View File

@@ -113,19 +113,21 @@ function M.get_lines(flattened_outline_items)
for index, _ in ipairs(line) do
-- all items start with a space (or two)
if config.options.show_guides then
-- makes the guides
if config.options.guides.enabled then
-- makes the guides and add guide markers
local guide_markers = config.options.guides.markers
if index == 1 then
line[index] = ' '
-- i f index is last, add a bottom marker if current item is last,
-- if index is last, add a bottom marker if current item is last,
-- else add a middle marker
elseif index == #line then
-- add fold markers
if config.options.fold_markers and folding.is_foldable(node) then
local fold_markers = config.options.fold_markers
if fold_markers and folding.is_foldable(node) then
if folding.is_folded(node) then
line[index] = config.options.fold_markers[1]
line[index] = fold_markers[1]
else
line[index] = config.options.fold_markers[2]
line[index] = fold_markers[2]
end
add_guide_hl(
@@ -136,16 +138,16 @@ function M.get_lines(flattened_outline_items)
-- the root level has no vertical markers
elseif depth > 1 then
if node.isLast then
line[index] = ui.markers.bottom
line[index] = guide_markers.bottom
add_guide_hl(
running_length,
running_length + vim.fn.strlen(ui.markers.bottom) - 1
running_length + vim.fn.strlen(guide_markers.bottom) - 1
)
else
line[index] = ui.markers.middle
line[index] = guide_markers.middle
add_guide_hl(
running_length,
running_length + vim.fn.strlen(ui.markers.middle) - 1
running_length + vim.fn.strlen(guide_markers.middle) - 1
)
end
end
@@ -153,11 +155,11 @@ function M.get_lines(flattened_outline_items)
-- vertical marker because there are items under us and we need
-- to point to those
elseif not node.hierarchy[index] and depth > 1 then
line[index + marker_space] = ui.markers.vertical
line[index + marker_space] = guide_markers.vertical
add_guide_hl(
running_length - 1 + 2 * marker_space,
running_length
+ vim.fn.strlen(ui.markers.vertical)
+ vim.fn.strlen(guide_markers.vertical)
- 1
+ 2 * marker_space
)

View File

@@ -1,12 +1,5 @@
local M = {}
M.markers = {
bottom = '',
middle = '',
vertical = '',
horizontal = '',
}
M.hovered_hl_ns = vim.api.nvim_create_namespace 'hovered_item'
function M.clear_hover_highlight(bufnr)

View File

@@ -32,7 +32,7 @@ function View:setup_view()
vim.api.nvim_win_set_option(self.winnr, 'wrap', config.options.wrap)
vim.api.nvim_win_set_option(self.winnr, 'linebreak', true) -- only has effect when wrap=true
vim.api.nvim_win_set_option(self.winnr, 'breakindent', true) -- only has effect when wrap=true
-- Would be nice to use ui.markers.vertical as part of showbreak to keep
-- Would be nice to use guides.markers.vertical as part of showbreak to keep
-- continuity of the tree UI, but there's currently no way to style the
-- color, apart from globally overriding hl-NonText, which will potentially
-- mess with other theme/user settings. So just use empty spaces for now.