summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorgi Kirilov <>2020-11-22 15:10:50 +0200
committerGeorgi Kirilov <>2023-10-04 18:24:59 +0800
commitadfb9800b111680a5b023ccda90d7f2b18e85244 (patch)
tree3173a753fb6aec2fa0daf6af6e562c9baa5bc7c2
parent508e8d162e67774a7658097943741ce2691cf0c7 (diff)
downloadvis-pairs-adfb9800b111680a5b023ccda90d7f2b18e85244.tar.gz
Fix abutting blocks
A regression in a3e9e92f caused even-numbered "automatic" blocks not to be detected: s/worked/didn't/ CSV, worked, didn't, worked, didn't, The above behaviour still works for quoted strings, where it's a feature. If it's desirable for other characters, it can be achieved by explicitly configuring a previously "automatic" block in the module's `map` table. (Examples - _ and * in Markdown.)
-rw-r--r--pairs.lua9
1 files changed, 6 insertions, 3 deletions
diff --git a/pairs.lua b/pairs.lua
index 93808f3..8220f66 100644
--- a/pairs.lua
+++ b/pairs.lua
@@ -91,7 +91,9 @@ local function any_captures(_, position, t)
if type(t) == "table" then
return position, t
end
- prev_match = position
+ if t then
+ prev_match = position - t
+ end
end
local function not_past(_, position, pos)
@@ -103,7 +105,7 @@ local function match_at(str, pattern, pos)
local string_pos = pos + 1
prev_match = 0
local I = l.Cp()
- local p = l.P{l.Cmt(l.Ct(I * (pattern/0) * I) * l.Cc(string_pos) / at_pos, any_captures) + 1 * l.Cmt(l.Cc(string_pos), not_past) * l.V(1)}
+ local p = l.P{l.Cmt(l.Ct(I * (pattern/0) * I) * l.Cc(string_pos) / at_pos * l.Cc(0), any_captures) + 1 * l.Cmt(l.Cc(string_pos), not_past) * l.V(1)}
local t = p:match(str)
if not t then return end
return t[1] - 1, t[#t] - 1
@@ -155,9 +157,10 @@ local function get_range(key, win, pos, file_data)
end
correction = range[1] - 1
local p = d[1] ~= d[2] and symmetric(d[1], d[2], c.escape, pos + 1) or asymmetric(d[1], pos + 1)
+ local can_abut = d[1] == d[2] and #d[1] == 1 and not (builtin_textobjects[key] or M.map[1][key] or M.map[win.syntax] and M.map[win.syntax][key])
local skip = c.escape and c.escape + 1 or 1
local data = c.range and file_data:sub(unpack(c.range)) or file_data
- local pattern = l.P{l.Cmt(p, any_captures) + skip * l.Cmt(l.Cc(pos + 1), not_past) * l.V(1)}
+ local pattern = l.P{l.Cmt(p * l.Cc(can_abut and 1 or 0), any_captures) + skip * l.Cmt(l.Cc(pos + 1), not_past) * l.V(1)}
prev_match = 0
offsets = {nth(pattern:match(data))}
offsets[3] = nil