From 1ac7b7af7f5ba2c67bbd8283a159b009207d73d2 Mon Sep 17 00:00:00 2001 From: Luckas Date: Fri, 19 Apr 2024 18:12:02 +0300 Subject: [PATCH] feat(conceal): add `min_length` option (#21) --- README.md | 1 + lua/tailwind-tools/conceal.lua | 18 +++++++++++------- lua/tailwind-tools/config.lua | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2aa79dd..c97e1b3 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ Here is the default configuration: }, conceal = { enabled = false, -- can be toggled by commands + min_length = nil, -- only conceal classes exceeding the provided length symbol = "󱏿", -- only a single character is allowed highlight = { -- extmark highlight options, see :h 'highlight' fg = "#38BDF8", diff --git a/lua/tailwind-tools/conceal.lua b/lua/tailwind-tools/conceal.lua index 2ebacd8..ad69a5a 100644 --- a/lua/tailwind-tools/conceal.lua +++ b/lua/tailwind-tools/conceal.lua @@ -16,16 +16,20 @@ local function set_conceal(bufnr) vim.api.nvim_buf_clear_namespace(bufnr, vim.g.tailwind_tools.color_ns, 0, -1) table.insert(state.conceal.active_buffers, bufnr) + local opts = config.options.conceal + for _, node in pairs(class_nodes) do local start_row, start_col, end_row, end_col = treesitter.get_class_range(node, bufnr) - vim.api.nvim_buf_set_extmark(bufnr, vim.g.tailwind_tools.conceal_ns, start_row, start_col, { - end_line = end_row, - end_col = end_col, - conceal = config.options.conceal.symbol, - hl_group = "TailwindConceal", - priority = 0, -- To ignore conceal hl_group when focused - }) + if not opts.min_length or node:byte_length() >= opts.min_length then + vim.api.nvim_buf_set_extmark(bufnr, vim.g.tailwind_tools.conceal_ns, start_row, start_col, { + end_line = end_row, + end_col = end_col, + conceal = opts.symbol, + hl_group = "TailwindConceal", + priority = 0, -- To ignore conceal hl_group when focused + }) + end end end diff --git a/lua/tailwind-tools/config.lua b/lua/tailwind-tools/config.lua index 5f4b8cc..0b594e4 100644 --- a/lua/tailwind-tools/config.lua +++ b/lua/tailwind-tools/config.lua @@ -13,6 +13,7 @@ M.options = { }, conceal = { enabled = false, + min_length = nil, symbol = "󱏿", highlight = { fg = "#38BDF8",