diff options
author | Lewis Russell <lewis6991@gmail.com> | 2022-11-12 13:14:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-12 13:14:21 +0000 |
commit | 3621c127a841b6aa5dbd12548b25f42534a91a26 (patch) | |
tree | 1bd0e2735446c916d9c3d47be1b88ef16b7642b4 /runtime/lua/vim | |
parent | 7335a67b5754255f0e892303a0f4e3521035e7d8 (diff) | |
parent | 07eb4263caa671de63186e9bbd650ec4b1fbce1a (diff) | |
download | rneovim-3621c127a841b6aa5dbd12548b25f42534a91a26.tar.gz rneovim-3621c127a841b6aa5dbd12548b25f42534a91a26.tar.bz2 rneovim-3621c127a841b6aa5dbd12548b25f42534a91a26.zip |
Merge pull request #20178 from vigoux/extmark-nospell
feat(extmarks): allow preventing spellchecking with spell = false
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/treesitter/highlighter.lua | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua index 83a26aff13..f5e5ca1988 100644 --- a/runtime/lua/vim/treesitter/highlighter.lua +++ b/runtime/lua/vim/treesitter/highlighter.lua @@ -164,7 +164,7 @@ function TSHighlighter:get_query(lang) end ---@private -local function on_line_impl(self, buf, line, spell) +local function on_line_impl(self, buf, line, is_spell_nav) self.tree:for_each_tree(function(tstree, tree) if not tstree then return @@ -201,17 +201,26 @@ local function on_line_impl(self, buf, line, spell) local start_row, start_col, end_row, end_col = node:range() local hl = highlighter_query.hl_cache[capture] - local is_spell = highlighter_query:query().captures[capture] == 'spell' + local capture_name = highlighter_query:query().captures[capture] + local spell = nil + if capture_name == 'spell' then + spell = true + elseif capture_name == 'nospell' then + spell = false + end + + -- Give nospell a higher priority so it always overrides spell captures. + local spell_pri_offset = capture_name == 'nospell' and 1 or 0 - if hl and end_row >= line and (not spell or is_spell) then + if hl and end_row >= line and (not is_spell_nav or spell ~= nil) then a.nvim_buf_set_extmark(buf, ns, start_row, start_col, { end_line = end_row, end_col = end_col, hl_group = hl, ephemeral = true, - priority = tonumber(metadata.priority) or 100, -- Low but leaves room below + priority = (tonumber(metadata.priority) or 100) + spell_pri_offset, -- Low but leaves room below conceal = metadata.conceal, - spell = is_spell, + spell = spell, }) end if start_row > line then |