From c591600d75786ddabdc14e958b6c4ae21937d16f Mon Sep 17 00:00:00 2001 From: tris203 Date: Wed, 22 May 2024 19:11:50 +0100 Subject: [PATCH] fix: next/prev paragraph spacing --- lua/precognition/vertical_motions.lua | 8 ++++---- tests/precognition/vertical_motions_spec.lua | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lua/precognition/vertical_motions.lua b/lua/precognition/vertical_motions.lua index 6e5da66..5cd3fc3 100644 --- a/lua/precognition/vertical_motions.lua +++ b/lua/precognition/vertical_motions.lua @@ -24,7 +24,7 @@ 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 @@ -32,7 +32,7 @@ function M.next_paragraph_line(bufnr) 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 @@ -54,7 +54,7 @@ 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 @@ -62,7 +62,7 @@ function M.prev_paragraph_line(bufnr) 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 diff --git a/tests/precognition/vertical_motions_spec.lua b/tests/precognition/vertical_motions_spec.lua index ac8e03f..1119622 100644 --- a/tests/precognition/vertical_motions_spec.lua +++ b/tests/precognition/vertical_motions_spec.lua @@ -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)