From 7e8b6824b9bc0a23de67f79cbe9b6249f1395874 Mon Sep 17 00:00:00 2001 From: tris203 Date: Sat, 1 Jun 2024 13:23:58 +0100 Subject: [PATCH] refactor: minor adjustments --- lua/precognition/horizontal_motions.lua | 6 +----- lua/precognition/utils.lua | 3 ++- tests/precognition/char_spec.lua | 1 + 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lua/precognition/horizontal_motions.lua b/lua/precognition/horizontal_motions.lua index cde6aa4..9b75318 100644 --- a/lua/precognition/horizontal_motions.lua +++ b/lua/precognition/horizontal_motions.lua @@ -132,11 +132,7 @@ 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 + --if remaining string is whitespace, return 0 local remaining = string.sub(str, offset) if remaining:match("^%s*$") and #remaining > 0 then return 0 diff --git a/lua/precognition/utils.lua b/lua/precognition/utils.lua index 29237e0..85c5b52 100644 --- a/lua/precognition/utils.lua +++ b/lua/precognition/utils.lua @@ -6,6 +6,7 @@ M.char_classes = { other = 1, word = 2, emoji = 3, + UNKNOWN = -1, } ---@param char string @@ -17,7 +18,7 @@ function M.char_class(char, big_word) local byte = string.byte(char) if byte == nil then - return cc.other + return cc.UNKNOWN end if char == " " or char == "\t" or char == "\0" then return cc.whitespace diff --git a/tests/precognition/char_spec.lua b/tests/precognition/char_spec.lua index 88f1b86..b1bbe36 100644 --- a/tests/precognition/char_spec.lua +++ b/tests/precognition/char_spec.lua @@ -9,6 +9,7 @@ describe("static classes", function() eq(cc.other, 1) eq(cc.word, 2) eq(cc.emoji, 3) + eq(cc.UNKNOWN, -1) end) end)