summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorgi Kirilov <>2020-11-22 15:10:50 +0200
committerGeorgi Kirilov <>2023-10-04 18:24:59 +0800
commit83fbeb65b818d1f23ba4c6422965b8c372b54247 (patch)
treeba7ec2c199d39dc4f01c80233a465ba6a9f50ad8
parentd43d7b5288fddbcd52a02f890e25f542916b2f0f (diff)
downloadvis-pairs-83fbeb65b818d1f23ba4c6422965b8c372b54247.tar.gz
Fix a crash
-rw-r--r--pairs.lua17
1 files changed, 8 insertions, 9 deletions
diff --git a/pairs.lua b/pairs.lua
index 7312030..9bed905 100644
--- a/pairs.lua
+++ b/pairs.lua
@@ -139,12 +139,11 @@ end
local function get_range(key, win, pos, file_data, count)
local d = get_pair(key, win)
if not d then return end
- local offsets, correction
repeat
local sel_range = selection_range(win, pos)
local c = escaping_context(win, sel_range, file_data)
local range = c.range or {1, #file_data}
- correction = range[1] - 1
+ local correction = range[1] - 1
pos = pos - correction
if sel_range then
sel_range.start = sel_range.start - correction
@@ -160,18 +159,18 @@ local function get_range(key, win, pos, file_data, count)
prev_match = 0
local hierarchy = pattern:match(data)
if hierarchy then
- offsets = {nth_innermost(hierarchy, count or 1)}
+ local offsets = {nth_innermost(hierarchy, count or 1)}
offsets[3] = nil -- a leftover from calling nth_innermost() with count higher than the hierarchy depth.
+ for _, o in ipairs(offsets) do
+ for i, v in ipairs(o) do
+ o[i] = v - 1 + correction
+ end
+ end
+ return unpack(offsets)
else
pos = correction - 1
end
until hierarchy or pos < 0
- for _, o in ipairs(offsets) do
- for i, v in ipairs(o) do
- o[i] = v - 1 + correction
- end
- end
- return unpack(offsets)
end
local function keep_last(acc, cur)