diff --git a/lua/various-textobjs/charwise-textobjs.lua b/lua/various-textobjs/charwise-textobjs.lua index de0ad2f..726b815 100644 --- a/lua/various-textobjs/charwise-textobjs.lua +++ b/lua/various-textobjs/charwise-textobjs.lua @@ -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(""):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()