diff --git a/lua/precognition/init.lua b/lua/precognition/init.lua index f6ad58d..60d8124 100644 --- a/lua/precognition/init.lua +++ b/lua/precognition/init.lua @@ -119,7 +119,10 @@ local function end_of_word(str, start) char_class(vim.fn.strcharpart(str, (offset - 1) + 1, 1)) local rev_offset - if c_class == 1 and next_char_class ~= 1 then + if + (c_class == 1 and next_char_class ~= 1) + or (next_char_class == 1 and c_class ~= 1) + then offset = offset + 1 char = vim.fn.strcharpart(str, offset - 1, 1) c_class = char_class(char) diff --git a/tests/precognition/char_spec.lua b/tests/precognition/char_spec.lua index 87ff063..ef3fd21 100644 --- a/tests/precognition/char_spec.lua +++ b/tests/precognition/char_spec.lua @@ -197,13 +197,20 @@ describe("boundaries", function() 6 ) ) - -- eq( - -- 5, - -- precognition.prev_word_boundary( - -- " myFunction(example, stuff)", - -- 16 - -- ) - -- ) + eq( + 5, + precognition.prev_word_boundary( + " myFunction(example, stuff)", + 15 + ) + ) + eq( + 15, + precognition.prev_word_boundary( + " myFunction(example, stuff)", + 16 + ) + ) eq( 16, precognition.prev_word_boundary( @@ -260,9 +267,13 @@ describe("boundaries", function() 29 ) ) - --TODO: This isnt right, it should ne 25, but i dont know the rules - --there is something odd if there is only one class 2 under the cursor - -- eq(25, precognition.prev_word_boundary(" myFunction(example, stuff)", 30)) + eq( + 25, + precognition.prev_word_boundary( + " myFunction(example, stuff)", + 30 + ) + ) end) it("can walk string with b", function() @@ -307,10 +318,14 @@ describe("boundaries", function() 14, precognition.end_of_word(" myFunction(example, stuff)", 5) ) - --TODO: These next two dont work either for the same reason as the previous - --something to do with the bracket being under the cursor - -- eq(15, precognition.end_of_word(" myFunction(example, stuff)", 14)) - -- eq(22, precognition.end_of_word(" myFunction(example, stuff)", 15)) + eq( + 15, + precognition.end_of_word(" myFunction(example, stuff)", 14) + ) + eq( + 22, + precognition.end_of_word(" myFunction(example, stuff)", 15) + ) eq( 22, precognition.end_of_word(" myFunction(example, stuff)", 16) @@ -328,7 +343,7 @@ describe("boundaries", function() precognition.end_of_word(" myFunction(example, stuff)", 25) ) eq( - 29, + 30, precognition.end_of_word(" myFunction(example, stuff)", 29) ) eq(