summaryrefslogtreecommitdiff
path: root/script-beta/proto/define.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta/proto/define.lua')
-rw-r--r--script-beta/proto/define.lua3
1 files changed, 2 insertions, 1 deletions
diff --git a/script-beta/proto/define.lua b/script-beta/proto/define.lua
index 61c4037c..3c955c95 100644
--- a/script-beta/proto/define.lua
+++ b/script-beta/proto/define.lua
@@ -11,7 +11,8 @@ function m.offset(lines, text, position)
local row = position.line + 1
local start = guide.lineRange(lines, row)
local offset = utf8.offset(text, position.character + 1, start)
- if text:sub(offset-1, offset):match '[%w_][^%w_]' then
+ if offset > #text
+ or text:sub(offset-1, offset):match '[%w_][^%w_]' then
offset = offset - 1
end
return offset