From 5794dc21129a8acc5f5b1fdbba48d8f0e5ec742b Mon Sep 17 00:00:00 2001 From: Chris Grieser <73286100+chrisgrieser@users.noreply.github.com> Date: Sat, 23 Dec 2023 19:55:55 +0100 Subject: [PATCH] refactor(subword): update to use multiple patterns --- lua/various-textobjs/charwise-textobjs.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lua/various-textobjs/charwise-textobjs.lua b/lua/various-textobjs/charwise-textobjs.lua index 9919773..35e25cd 100644 --- a/lua/various-textobjs/charwise-textobjs.lua +++ b/lua/various-textobjs/charwise-textobjs.lua @@ -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("") == fn.expand(""):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