From e8558a58a0e19bbc0d150af9262a191de47a841d Mon Sep 17 00:00:00 2001 From: simrat39 Date: Sun, 18 Apr 2021 19:59:19 -0700 Subject: [PATCH] symbols-outline: Add basic guides implementation Shows guides around the outline (looks cool) --- lua/symbols-outline.lua | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/lua/symbols-outline.lua b/lua/symbols-outline.lua index f70a619..425d2d7 100644 --- a/lua/symbols-outline.lua +++ b/lua/symbols-outline.lua @@ -30,6 +30,13 @@ D.state = { outline_buf = nil } +local markers = { + bottom = "└", + middle = "├", + vertical = "│", + horizontal = "─" +} + function D.goto_location() local current_line = vim.api.nvim_win_get_cursor(D.state.outline_win)[1] local node = D.state.linear_outline_items[current_line] @@ -76,10 +83,28 @@ local function make_linear(outline_items) end local function write(outline_items, bufnr, winnr) - for _, value in ipairs(outline_items) do - vim.api.nvim_buf_set_lines(bufnr, -2, -2, false, { - string.rep(" ", value.depth * 2) .. value.icon .. " " .. value.name - }) + for index, value in ipairs(outline_items) do + local line = " " + local isLast = index == #outline_items + + if value.depth > 1 then + for i = 0, value.depth - 1, 1 do + if i == value.depth - 1 and not isLast then + -- do nothing for now :) + -- line = line .. markers.horizontal + elseif isLast and i % 2 == 0 then + line = line .. markers.bottom + elseif i % 2 == 0 then + line = line .. markers.middle + elseif i % 2 ~= 0 and not isLast then + line = line .. markers.horizontal + end + end + line = line .. " " + end + + vim.api.nvim_buf_set_lines(bufnr, -2, -2, false, + {line .. value.icon .. " " .. value.name}) vim.api.nvim_buf_set_keymap(bufnr, "n", "", ":lua require('symbols-outline').goto_location()", {})