1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 07:20:04 +08:00

feat(zkbrowser): use <LeftRelease> to filter tag

This commit is contained in:
Eric Wong 2024-12-11 10:10:34 +08:00
parent 4b61259a80
commit fb7bb88485
2 changed files with 55 additions and 0 deletions

View File

@ -16,6 +16,7 @@ vim.opt_local.keywordprg = ':ZkHover -preview'
vim.opt_local.tagfunc = 'v:lua.zettelkasten.tagfunc'
local win = require('spacevim.api.vim.window')
local hi = require('spacevim.api.vim.highlight')
require('zettelkasten').add_hover_command()
@ -53,6 +54,17 @@ if vim.fn.mapcheck('[I', 'n') == '' then
vim.cmd('ZkBrowse')
end,
})
vim.api.nvim_buf_set_keymap(0, 'n', '<LeftRelease>', '', {
noremap = true,
silent = true,
nowait = true,
callback = function()
if hi.syntax_at() == 'ZettelKastenTags' then
vim.cmd('ZkBrowse #' .. vim.fn.expand('<cword>') )
end
end,
})
end
local config = require('zettelkasten.config')

View File

@ -101,4 +101,47 @@ function M.hi_separator(a, b)
M.hi(hi_b_a)
end
local function get_color(name)
local c = vim.api.nvim_get_hl(0, { name = name })
if c.link then
return get_color(c.link)
else
return c
end
end
function M.syntax_at(...)
local lnum = select(1, ...) or vim.fn.line('.')
local col = select(2, ...) or vim.fn.col('.')
local inspect = vim.inspect_pos(0, lnum - 1, col - 1)
local name, hl
if #inspect.semantic_tokens > 0 then
local token, priority = {}, 0
for _, semantic_token in ipairs(inspect.semantic_tokens) do
if semantic_token.opts.priority > priority then
priority = semantic_token.opts.priority
token = semantic_token
end
end
if token then
name = token.opts.hl_group_link
hl = vim.api.nvim_get_hl(0, { name = token.opts.hl_group_link })
end
elseif #inspect.treesitter > 0 then
for i = #inspect.treesitter, 1, -1 do
name = inspect.treesitter[i].hl_group_link
hl = vim.api.nvim_get_hl(0, { name = name })
if hl.fg then
break
end
end
else
name = vim.fn.synIDattr(vim.fn.synID(vim.fn.line('.'), vim.fn.col('.'), 1), 'name', 'gui')
hl = get_color(name)
end
return name, hl
end
return M