Skip to content

Commit

Permalink
refactor(subword): update to use multiple patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Dec 23, 2023
1 parent 9b16470 commit 5794dc2
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lua/various-textobjs/charwise-textobjs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,10 @@ end

---@param scope "inner"|"outer" outer includes trailing -_
function M.subword(scope)
local pattern = "()%w[%l%d]+([ _-]?)"

-- adjust pattern when word under cursor is all uppercase to handle
-- subwords of SCREAMING_SNAKE_CASE variables
local upperCaseWord = fn.expand("<cword>") == fn.expand("<cword>"):upper()
if upperCaseWord then pattern = "()[%u%d]+([ _-]?)" end

-- forward looking results in unexpected behavior for subword
local pattern = {
"()%w[%l%d]+([_%- ]?)", -- camelCase or lowercase
"()[%u%d]+([_%- ]?)", -- UPPER_CASE or digits
}
selectTextobj(pattern, scope, 0)
end

Expand Down

0 comments on commit 5794dc2

Please sign in to comment.