From a373c38be54a7fa5ef8883d8b7e3dd2f6eec1bb5 Mon Sep 17 00:00:00 2001 From: tris203 Date: Sat, 1 Jun 2024 13:29:16 +0100 Subject: [PATCH] fix: don't overload copy of Vim char class. --- lua/precognition/horizontal_motions.lua | 4 ++++ tests/precognition/char_spec.lua | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lua/precognition/horizontal_motions.lua b/lua/precognition/horizontal_motions.lua index abff9b7..cde6aa4 100644 --- a/lua/precognition/horizontal_motions.lua +++ b/lua/precognition/horizontal_motions.lua @@ -132,6 +132,10 @@ function M.prev_word_boundary(str, cursorcol, linelen, big_word) while utils.char_class(char, big_word) == c_class and offset >= 0 do offset = offset - 1 char = vim.fn.strcharpart(str, offset - 1, 1) + if char == "" then + -- Gone outside the line boundary, so break. + break + end --if remaining string is whitespace, return nil_wrap local remaining = string.sub(str, offset) if remaining:match("^%s*$") and #remaining > 0 then diff --git a/tests/precognition/char_spec.lua b/tests/precognition/char_spec.lua index fb660da..88f1b86 100644 --- a/tests/precognition/char_spec.lua +++ b/tests/precognition/char_spec.lua @@ -63,11 +63,6 @@ describe("big_word classing", function() eq(utils.char_class("", false), 2) eq(utils.char_class("", false), 2) end) - - it("can class the empty string", function() - eq(utils.char_class("", true), 3) - eq(utils.char_class("", false), 3) - end) end) describe("pad arrays", function()