From 7e6bb85af1ffccc01f7504cd427fc8123d3179d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sun, 25 Oct 2020 19:50:20 +0800 Subject: =?UTF-8?q?#234=20=E4=BF=AE=E6=AD=A3=E4=B8=80=E4=B8=AA=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=BD=8D=E7=BD=AE=E8=B6=8A=E7=95=8C=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/proto/define.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'script-beta') diff --git a/script-beta/proto/define.lua b/script-beta/proto/define.lua index 92403518..3afd5dc7 100644 --- a/script-beta/proto/define.lua +++ b/script-beta/proto/define.lua @@ -11,6 +11,9 @@ local m = {} function m.offset(lines, text, position) local row = position.line + 1 local start = guide.lineRange(lines, row) + if start >= #text then + return 0 + end local offset = utf8.offset(text, position.character + 1, start) return offset - 1 end @@ -23,6 +26,9 @@ end function m.offsetOfWord(lines, text, position) local row = position.line + 1 local start = guide.lineRange(lines, row) + if start >= #text then + return 0 + end local offset = utf8.offset(text, position.character + 1, start) if offset > #text or text:sub(offset-1, offset):match '[%w_][^%w_]' then -- cgit v1.2.3