From 3278b50f2716b6cba32882cea88823bf67face2b Mon Sep 17 00:00:00 2001 From: Chris Grieser <73286100+chrisgrieser@users.noreply.github.com> Date: Thu, 26 Dec 2024 12:02:19 +0100 Subject: [PATCH] feat: make patterns for `url` object configurable --- README.md | 5 +++++ lua/various-textobjs/config.lua | 5 +++++ lua/various-textobjs/textobjs/charwise.lua | 4 ++-- lua/various-textobjs/textobjs/charwise/core.lua | 4 +++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 520ec2b..70ef8ac 100644 --- a/README.md +++ b/README.md @@ -167,6 +167,11 @@ require("various-textobjs").setup { diagnostic = { wrap = true, }, + url = { + patterns = { + [[%l%l%l-://[^%s)"'`]+]], -- exclude ) for md, "'` for strings + }, + }, }, notify = { diff --git a/lua/various-textobjs/config.lua b/lua/various-textobjs/config.lua index 717e938..f4f4ebd 100644 --- a/lua/various-textobjs/config.lua +++ b/lua/various-textobjs/config.lua @@ -40,6 +40,11 @@ local defaultConfig = { diagnostic = { wrap = true, }, + url = { + patterns = { + [[%l%l%l-://[^%s)"'`]+]], -- exclude ) for md, "'` for strings + }, + }, }, notify = { diff --git a/lua/various-textobjs/textobjs/charwise.lua b/lua/various-textobjs/textobjs/charwise.lua index dcc3c16..fa66c04 100644 --- a/lua/various-textobjs/textobjs/charwise.lua +++ b/lua/various-textobjs/textobjs/charwise.lua @@ -209,9 +209,9 @@ function M.number(scope) end function M.url() - local pattern = [[%l%l%l-://[^%s)"'`]+]] -- excludes: )"'` and whitespace + local urlPatterns = require("various-textobjs.config").config.textobjs.url.patterns local bigForward = require("various-textobjs.config").config.forwardLooking.big - core.selectClosestTextobj(pattern, "outer", bigForward) + core.selectClosestTextobj(urlPatterns, "outer", bigForward) end ---@param scope "inner"|"outer" inner excludes the leading dot diff --git a/lua/various-textobjs/textobjs/charwise/core.lua b/lua/various-textobjs/textobjs/charwise/core.lua index fd802b3..b6fe123 100644 --- a/lua/various-textobjs/textobjs/charwise/core.lua +++ b/lua/various-textobjs/textobjs/charwise/core.lua @@ -108,7 +108,9 @@ function M.selectClosestTextobj(patterns, scope, lookForwLines) local cur = {} cur.row, cur.startCol, cur.endCol = M.getTextobjPos(pattern, scope, lookForwLines) if cur.row and cur.startCol and cur.endCol then - if patternName:find("tieloser") then cur.tieloser = true end + if type(patternName) == "string" and patternName:find("tieloser") then + cur.tieloser = true + end cur.distance = cur.startCol - cursorCol cur.endDistance = cursorCol - cur.endCol cur.cursorOnObj = cur.distance <= 0 and cur.endDistance <= 0