aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/lua/vim/treesitter/highlighter.lua4
-rw-r--r--test/functional/treesitter/highlight_spec.lua63
2 files changed, 40 insertions, 27 deletions
diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua
index 003f7e0169..cd5c67d816 100644
--- a/runtime/lua/vim/treesitter/highlighter.lua
+++ b/runtime/lua/vim/treesitter/highlighter.lua
@@ -377,11 +377,15 @@ function TSHighlighter._on_spell_nav(_, _, buf, srow, _, erow, _)
return
end
+ -- Do not affect potentially populated highlight state. Here we just want a temporary
+ -- empty state so the C code can detect whether the region should be spell checked.
+ local highlight_states = self._highlight_states
self:prepare_highlight_states(srow, erow)
for row = srow, erow do
on_line_impl(self, buf, row, true)
end
+ self._highlight_states = highlight_states
end
---@private
diff --git a/test/functional/treesitter/highlight_spec.lua b/test/functional/treesitter/highlight_spec.lua
index 69984b3233..05c0cdc01e 100644
--- a/test/functional/treesitter/highlight_spec.lua
+++ b/test/functional/treesitter/highlight_spec.lua
@@ -1008,39 +1008,48 @@ describe('treesitter highlighting (markdown)', function()
before_each(function()
screen = Screen.new(40, 6)
screen:attach()
- screen:set_default_attr_ids {
- [1] = { foreground = Screen.colors.Blue1 },
- [2] = { bold = true, foreground = Screen.colors.Blue1 },
- [3] = { bold = true, foreground = Screen.colors.Brown },
- [4] = { foreground = Screen.colors.Cyan4 },
- [5] = { foreground = Screen.colors.Magenta1 },
- }
+ exec_lua([[
+ vim.bo.filetype = 'markdown'
+ vim.treesitter.start()
+ ]])
end)
it('supports hyperlinks', function()
local url = 'https://example.com'
insert(string.format('[This link text](%s) is a hyperlink.', url))
- exec_lua([[
- vim.bo.filetype = 'markdown'
- vim.treesitter.start()
- ]])
+ screen:add_extra_attr_ids({
+ [100] = { foreground = Screen.colors.DarkCyan, url = 'https://example.com' },
+ })
+ screen:expect({
+ grid = [[
+ {25:[}{100:This link text}{25:](}{28:https://example.com}{25:)} is|
+ a hyperlink^. |
+ {1:~ }|*3
+ |
+ ]],
+ })
+ end)
- screen:expect {
+ it('works with spellchecked and smoothscrolled topline', function()
+ insert([[
+- $f(0)=\sum_{k=1}^{\infty}\frac{2}{\pi^{2}k^{2}}+\lim_{w \to 0}x$.
+
+```c
+printf('Hello World!');
+```
+ ]])
+ command('set spell smoothscroll')
+ feed('gg<C-E>')
+ screen:add_extra_attr_ids({ [100] = { undercurl = true, special = Screen.colors.Red } })
+ screen:expect({
grid = [[
- {4:[}{6:This link text}{4:](}{7:https://example.com}{4:)} is|
- a hyperlink^. |
- {2:~ }|*3
- |
- ]],
- attr_ids = {
- [1] = { foreground = Screen.colors.Blue1 },
- [2] = { bold = true, foreground = Screen.colors.Blue1 },
- [3] = { bold = true, foreground = Screen.colors.Brown },
- [4] = { foreground = Screen.colors.Cyan4 },
- [5] = { foreground = Screen.colors.Magenta },
- [6] = { foreground = Screen.colors.Cyan4, url = url },
- [7] = { underline = true, foreground = Screen.colors.SlateBlue },
- },
- }
+ {1:<<<}k^{2}}+\{100:lim}_{w \to 0}x$^. |
+ |
+ {18:```}{15:c} |
+ {25:printf}{16:(}{26:'Hello World!'}{16:);} |
+ {18:```} |
+ |
+ ]],
+ })
end)
end)