Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: next/prev paragraph spacing #30

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading