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(horizontal_motions): handle quoted strings in word boundaries #68

Merged
merged 2 commits into from
Jun 14, 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
6 changes: 5 additions & 1 deletion lua/precognition/horizontal_motions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,13 @@ function M.end_of_word(str, cursorcol, linelen, big_word)
if c_class == cc.whitespace or next_char_class == cc.whitespace then
local next_word_start = M.next_word_boundary(str, cursorcol, linelen, big_word)
if next_word_start then
c_class = utils.char_class(vim.fn.strcharpart(str, next_word_start - 1, 1), big_word)
next_char_class = utils.char_class(vim.fn.strcharpart(str, (next_word_start - 1) + 1, 1), big_word)
--next word is single char
if next_char_class == cc.whitespace then
--next word is single char
rev_offset = next_word_start
elseif c_class == cc.punctuation and next_char_class ~= cc.punctuation then
--next word starts with punctuation
rev_offset = next_word_start
else
rev_offset = M.end_of_word(str, next_word_start, linelen, big_word)
Expand Down
8 changes: 8 additions & 0 deletions tests/precognition/horizontal_motions_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,12 @@ describe("edge case", function()
eq(3, hm.prev_word_boundary(str, 18, len, true))
eq(3, hm.prev_word_boundary(str, 5, len, false))
end)

it("quoted strings", function()
local str = 'this = "that"'
eq(8, hm.end_of_word(str, 6, #str, false))

str = 'b = "^", c = 2 },'
eq(8, hm.end_of_word(str, 3, #str, false))
end)
end)
Loading