From 7b913f9accb3739effdf2982789090cc570b9ec8 Mon Sep 17 00:00:00 2001 From: Shawon Date: Sat, 5 Oct 2024 23:45:19 +0600 Subject: [PATCH] feat: Ability to disable hybrid modes behavior when inside specific nodes Closes #154 --- lua/definitions.lua | 1 + lua/markview.lua | 2 ++ markview.nvim.wiki | 2 +- plugin/markview.lua | 10 ++++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lua/definitions.lua b/lua/definitions.lua index 38959ad..aef0dcd 100644 --- a/lua/definitions.lua +++ b/lua/definitions.lua @@ -21,6 +21,7 @@ ---@field horizontal_rules markview.conf.hrs ---@field html markview.conf.html ---@field hybrid_modes? string[] Modes where hybrid mode should be enabled +---@field ignore_nodes? string[] Tree-sitter nodes to ignore when using hybrid modes ---@field initial_state boolean Whether to show the preview at start or not ---@field injections markview.conf.injections ---@field inline_codes markview.conf.inline_codes diff --git a/lua/markview.lua b/lua/markview.lua index 17ed66c..379c7d2 100644 --- a/lua/markview.lua +++ b/lua/markview.lua @@ -104,7 +104,9 @@ markview.configuration = { hybrid_modes = nil, + ignore_nodes = nil, initial_state = true, + max_file_length = 1000, modes = { "n", "no", "c" }, render_distance = 100, diff --git a/markview.nvim.wiki b/markview.nvim.wiki index 65feb10..1489791 160000 --- a/markview.nvim.wiki +++ b/markview.nvim.wiki @@ -1 +1 @@ -Subproject commit 65feb10a8539b312b601e7d43bbb10ee1d633a30 +Subproject commit 148979129d010643cffefb82888f7396376c6eb3 diff --git a/plugin/markview.lua b/plugin/markview.lua index 84d0de7..edec2c8 100644 --- a/plugin/markview.lua +++ b/plugin/markview.lua @@ -48,6 +48,16 @@ local buf_render = function (buffer) -- Get the cursor local cursor = vim.api.nvim_win_get_cursor(win or 0); + local node = vim.treesitter.get_node({ bufnr = buffer, pos = { cursor[1] - 1, cursor[2]} }); + + --- Don't hide stuff on specific nodes + while node:parent() do + if vim.list_contains(markview.configuration.ignore_nodes or {}, node:type()) then + return; + end + + node = node:parent(); + end -- Range to start & stop parsing local start = math.max(0, cursor[1] - 1);