Skip to content

Commit

Permalink
chore: minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Dec 25, 2023
1 parent 2c64774 commit ded733b
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lua/various-textobjs/charwise-textobjs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ end

--------------------------------------------------------------------------------

---Seek and select characterwise text object based on pattern.
---Seek and select characterwise a text object based on one pattern.
---CAVEAT multi-line-objects are not supported
---@param pattern string lua pattern. REQUIRES two capture groups marking the
---two additions for the outer variant of the textobj. Use an empty capture group
---when there is no difference between inner and outer on that side.
---(Essentially, the two capture groups work as lookbehind and lookahead.)
---CAVEAT multi-line-objects are not supported
---Essentially, the two capture groups work as lookbehind and lookahead.
---@param scope "inner"|"outer"
---@param lookForwL integer
---@return pos? startPos
Expand Down Expand Up @@ -85,6 +85,7 @@ end
---@return boolean -- whether textobj search was successful
local function selectTextobj(patterns, scope, lookForwL)
local closestObj

if type(patterns) == "string" then
local startPos, endPos = searchTextobj(patterns, scope, lookForwL)
if startPos and endPos then closestObj = { startPos, endPos } end
Expand All @@ -108,13 +109,10 @@ local function selectTextobj(patterns, scope, lookForwL)

-- this condition for rows suffices since `searchTextobj` does not
-- return multi-line-objects
if row < closestRow then
if (row < closestRow) or (row == closestRow and isCloserInRow) then
closestRow = row
shortestDist = distance
closestObj = { startPos, endPos }
elseif row == closestRow and isCloserInRow then
shortestDist = distance
closestObj = { startPos, endPos }
end
end
end
Expand Down

0 comments on commit ded733b

Please sign in to comment.