From b13a191fbbfe427d1aadaf41419520c43abee141 Mon Sep 17 00:00:00 2001 From: Karim Abou Zeid Date: Sat, 5 Feb 2022 13:16:19 +0100 Subject: [PATCH] Fix `ZkNewFromTitleSelection` from a visual block selection (#35) --- lua/zk/util.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/zk/util.lua b/lua/zk/util.lua index beec8e0..2f06c65 100644 --- a/lua/zk/util.lua +++ b/lua/zk/util.lua @@ -64,8 +64,9 @@ function M.get_text_in_range(range) if vim.tbl_isempty(lines) then return nil end - lines[#lines] = string.sub(lines[#lines], 1, B.character) - lines[1] = string.sub(lines[1], A.character + 1) + local MAX_STRING_SUB_INDEX = 2^31 - 1 -- LuaJIT only supports 32bit integers for `string.sub` (in block selection B.character is 2^31) + lines[#lines] = string.sub(lines[#lines], 1, math.min(B.character, MAX_STRING_SUB_INDEX)) + lines[1] = string.sub(lines[1], math.min(A.character + 1, MAX_STRING_SUB_INDEX)) return table.concat(lines, "\n") end