Skip to content

Commit

Permalink
Merge branch 'main' into custom_highlight
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 authored May 22, 2024
2 parents 6ff41a3 + 7a4c5eb commit f05a16a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lua/precognition/vertical_motions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ function M.next_paragraph_line(bufnr)
local cursorline, _ = unpack(vim.api.nvim_win_get_cursor(0))
while not found and cursorline < visibleline do
local cursorlinecontent = buffcontent[cursorline]
while cursorline < visibleline and cursorlinecontent:match("^%s*$") do
while cursorline < visibleline and cursorlinecontent:match("^[\n\r]*$") do
cursorline = cursorline + 1
cursorlinecontent = buffcontent[cursorline]
end
-- find next blank line below
while cursorline < visibleline and not found do
cursorline = cursorline + 1
cursorlinecontent = buffcontent[cursorline]
if cursorlinecontent:match("^%s*$") then
if cursorlinecontent:match("^[\n\r]*$") then
found = true
end
end
Expand All @@ -54,15 +54,15 @@ function M.prev_paragraph_line(bufnr)
local cursorline, _ = unpack(vim.api.nvim_win_get_cursor(0))
while not found and cursorline > visibleline do
local cursorlinecontent = buffcontent[cursorline]
while cursorline > visibleline and cursorlinecontent:match("^%s*$") do
while cursorline > visibleline and cursorlinecontent:match("^[\n\r]*$") do
cursorline = cursorline - 1
cursorlinecontent = buffcontent[cursorline]
end
-- find next blank line above
while cursorline > visibleline and not found do
cursorline = cursorline - 1
cursorlinecontent = buffcontent[cursorline]
if cursorlinecontent:match("^%s*$") then
if cursorlinecontent:match("^[\n\r]*$") then
found = true
end
end
Expand Down
20 changes: 20 additions & 0 deletions tests/precognition/vertical_motions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,24 @@ describe("gutter motion locations", function()
local next_line = vm.next_paragraph_line(testBuf)
eq(8, next_line)
end)

it("lines with just whitespace as part of a paragraph", function()
local testBuf = vim.api.nvim_create_buf(true, true)
vim.api.nvim_buf_set_lines(testBuf, 0, -1, false, {
"ABC",
"DEF",
" ",
"GHI",
"",
"JKL",
"",
"MNO",
})

vim.api.nvim_set_current_buf(testBuf)
vim.api.nvim_win_set_cursor(0, { 1, 0 })

local next_line = vm.next_paragraph_line(testBuf)
eq(5, next_line)
end)
end)

0 comments on commit f05a16a

Please sign in to comment.