fix(treesitter): fix spell navigation on first line (#37361)

Problem:  Spell navigation skips words on the first line because
          _on_spell_nav passes an empty range (0,0) to the highlighter.

Solution: Use math.max(erow, srow + 1) to ensure a valid search window.

Signed-off-by: ashab-k <ashabkhan2000@gmail.com>
This commit is contained in:
ashab-k
2026-01-15 07:50:24 +05:30
committed by GitHub
parent 4451adbf84
commit 86c939ba91
2 changed files with 22 additions and 1 deletions

View File

@@ -508,9 +508,10 @@ function TSHighlighter._on_spell_nav(_, _, buf, srow, _, erow, _)
-- 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
local search_erow = math.max(erow, srow + 1)
self:prepare_highlight_states(srow, erow)
on_range_impl(self, buf, srow, 0, erow, 0, true, false)
on_range_impl(self, buf, srow, 0, search_erow, 0, true, false)
self._highlight_states = highlight_states
end

View File

@@ -1453,3 +1453,23 @@ it('no nil index for missing highlight query', function()
vim.treesitter.highlighter.new(parser)
]])
end)
it('spell navigation correctly wraps back to the first line (Row 0) #36970', function()
clear()
insert([[
mispelledone
mispelledtwo]])
command('set spell')
command('set wrapscan')
exec_lua(function()
vim.treesitter.start(0, 'markdown')
end)
api.nvim_win_set_cursor(0, { 2, 0 })
feed(']s')
local pos = api.nvim_win_get_cursor(0)
eq(1, pos[1], 'Should have wrapped back to Line 1')
end)