Skip to content

Commit

Permalink
feat: make patterns for url object configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Dec 26, 2024
1 parent a357d3e commit 3278b50
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ require("various-textobjs").setup {
diagnostic = {
wrap = true,
},
url = {
patterns = {
[[%l%l%l-://[^%s)"'`]+]], -- exclude ) for md, "'` for strings
},
},
},

notify = {
Expand Down
5 changes: 5 additions & 0 deletions lua/various-textobjs/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ local defaultConfig = {
diagnostic = {
wrap = true,
},
url = {
patterns = {
[[%l%l%l-://[^%s)"'`]+]], -- exclude ) for md, "'` for strings
},
},
},

notify = {
Expand Down
4 changes: 2 additions & 2 deletions lua/various-textobjs/textobjs/charwise.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lua/various-textobjs/textobjs/charwise/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3278b50

Please sign in to comment.