Skip to content

Commit

Permalink
feat(subword): when deleting start of camelCase, prevent PascalCase #113
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Dec 3, 2024
1 parent c95e268 commit a7e8387
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lua/various-textobjs/charwise-textobjs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ function M.subword(scope)
-- `o`: to start of sel, `h`: select char before `o`: back to end of selection
u.normal("oho")
end

-- If deleting the start of a camelCased subword, the result should still be
-- camelCased and not PascalCased (see #113).
local originalWasCamelCased = vim.fn.expand("<cword>"):find("%l%u") ~= nil
local charAfter = line:sub(endCol + 1, endCol + 1)
local isStartOfWord = line:sub(startCol - 1, startCol - 1) == " "
local isDeletion = vim.v.operator == "d"
if originalWasCamelCased and charAfter:find("%u") and isStartOfWord and isDeletion then
local updatedLine = line:sub(1, endCol) .. charAfter:lower() .. line:sub(endCol + 2)
vim.api.nvim_buf_set_lines(0, startRow - 1, startRow, false, { updatedLine })
end
end

function M.toNextClosingBracket()
Expand Down

0 comments on commit a7e8387

Please sign in to comment.