Skip to content

Commit 650f9a4

Browse files
committed
refactor: improve readability of matchPos finding
1 parent b0ef06f commit 650f9a4

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lua/spider/motion-logic.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ local strFuncs = require("spider.extras.utf8-support").stringFuncs
1313
local function getMatchpos(line, pattern, endOfWord, searchOffset)
1414
-- special case: pattern with unescaped ^/$, since there can only be one
1515
-- match and since gmatch won't work with them
16-
local endsWithUnescapedDollar = pattern:find("f[%$]$$") -- not `:find("$$")`, could be escaped $, see #63
17-
if pattern:find("^^") or endsWithUnescapedDollar then
16+
17+
-- trailing $ could be escaped $, see #63
18+
local endsWithUnescapedDollar = vim.endswith(pattern, "$") and not vim.endswith(pattern, "%$")
19+
if vim.startswith(pattern, "^") or endsWithUnescapedDollar then
1820
-- checking for high col count for virtualedit
1921
if endsWithUnescapedDollar and searchOffset > strFuncs.len(line) then return false end
20-
if pattern:find("^^") and searchOffset ~= 0 then return false end
22+
if vim.startswith(pattern, "^") and searchOffset ~= 0 then return false end
2123

2224
local startPos, endPos = strFuncs.find(line, pattern)
2325
if not startPos or not endPos then return false end
@@ -27,6 +29,8 @@ local function getMatchpos(line, pattern, endOfWord, searchOffset)
2729
return false
2830
end
2931

32+
-----------------------------------------------------------------------------
33+
3034
-- `()` makes gmatch return the position of that group
3135
pattern = endOfWord and (pattern .. "()") or ("()" .. pattern)
3236

0 commit comments

Comments
 (0)