Skip to content

Commit

Permalink
Fix bookmarking with mini.visits
Browse files Browse the repository at this point in the history
  • Loading branch information
Rypac committed Sep 12, 2024
1 parent 9cc225d commit 05ac45d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion nvim/lua/plugin/mini-statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ vim.api.nvim_create_autocmd("BufEnter", {
group = vim.api.nvim_create_augroup("UserBookmarkState", { clear = true }),
callback = function(args)
local ok, visits = pcall(require, "mini.visits")
vim.b[args.buf].bookmark = ok and #visits.list_labels(nil, nil, { filter = "bookmark" }) > 0
vim.b[args.buf].bookmark = ok
and args.file ~= ""
and #visits.list_labels(args.file, vim.uv.cwd(), { filter = "bookmark" }) > 0
end,
})

Expand Down
12 changes: 9 additions & 3 deletions nvim/lua/plugin/mini-visits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,20 @@ end, {
})

vim.keymap.set("n", "<C-h>", function()
local path = vim.api.nvim_buf_get_name(0)
if path == "" then
return
end

local silent = visits.config.silent
visits.config.silent = true

local has_bookmark = vim.list_contains(visits.list_labels(), "bookmark")
local cwd = vim.uv.cwd()
local has_bookmark = #visits.list_labels(path, cwd, { filter = "bookmark" }) > 0
if not has_bookmark then
visits.add_label("bookmark")
visits.add_label("bookmark", path, cwd)
else
visits.remove_label("bookmark")
visits.remove_label("bookmark", path, cwd)
end

visits.config.silent = silent
Expand Down

0 comments on commit 05ac45d

Please sign in to comment.