From f59ed12ed5c56e629df05fcd30ef07693ce0d0c9 Mon Sep 17 00:00:00 2001 From: Lintao Date: Wed, 25 Dec 2024 22:44:53 +0800 Subject: [PATCH] config bookmark render format --- lua/bookmarks/config.lua | 2 ++ lua/bookmarks/domain/location.lua | 7 +++++++ lua/bookmarks/tree/init.lua | 6 ------ lua/bookmarks/tree/render/init.lua | 7 ++++++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lua/bookmarks/config.lua b/lua/bookmarks/config.lua index 95ad916..0094da0 100644 --- a/lua/bookmarks/config.lua +++ b/lua/bookmarks/config.lua @@ -65,6 +65,8 @@ local default_config = { ---@type { keymap: { [string]: string|string[] } } treeview = { + ---@type fun(node: Bookmarks.Node): string | nil + render_bookmark = nil, -- stylua: ignore start keymap = { quit = { "q", "" }, -- Close the tree view window and return to previous window diff --git a/lua/bookmarks/domain/location.lua b/lua/bookmarks/domain/location.lua index 6bcc4ab..cd4e634 100644 --- a/lua/bookmarks/domain/location.lua +++ b/lua/bookmarks/domain/location.lua @@ -25,4 +25,11 @@ M.same_line = function(a, b) return a.line == b.line and a.path == b.path end +---Get just the file name from a location +---@param location Bookmarks.Location +---@return string # the file name without path +function M.get_file_name(location) + return vim.fn.fnamemodify(location.path, ":t") +end + return M diff --git a/lua/bookmarks/tree/init.lua b/lua/bookmarks/tree/init.lua index 0d3875d..f5d7bbd 100644 --- a/lua/bookmarks/tree/init.lua +++ b/lua/bookmarks/tree/init.lua @@ -40,12 +40,6 @@ local function register_local_shortcuts(buf) end end -local function clean_tree_cache(buf) - vim.b[buf]._bm_context = nil - vim.b[buf]._bm_tree_cut = nil -end - ----Toggle the tree view ---Toggle the tree view function M.toggle() local cur_window = vim.api.nvim_get_current_win() diff --git a/lua/bookmarks/tree/render/init.lua b/lua/bookmarks/tree/render/init.lua index 042709c..5d3824b 100644 --- a/lua/bookmarks/tree/render/init.lua +++ b/lua/bookmarks/tree/render/init.lua @@ -1,6 +1,7 @@ local Context = require("bookmarks.tree.ctx") local Repo = require("bookmarks.domain.repo") local Highlight = require("bookmarks.tree.render.highlight") +local Location = require("bookmarks.domain.location") local INTENT = " " local M = {} @@ -37,7 +38,8 @@ end local function render_bookmark(node) local book_icon = "◉" - local name = node.name + local filename = Location.get_file_name(node.location) + local name = filename .. ": " .. node.name if node.name == "" then name = "[Untitled]" end @@ -71,6 +73,9 @@ end ---@return string local function render_context(node, deep, active_list_id) if node.type == "bookmark" then + if vim.g.bookmarks_config.treeview.render_bookmark then + return string.rep(INTENT, deep) .. vim.g.bookmarks_config.treeview.render_bookmark(node) + end return string.rep(INTENT, deep) .. render_bookmark(node) else return string.rep(INTENT, deep) .. render_list(node, active_list_id)