From dc17984bcdd5afc7f74a05234b7f7f8a5eb7766d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 28 Jan 2021 20:28:14 +0800 Subject: fix files.offset --- script/files.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'script') diff --git a/script/files.lua b/script/files.lua index 7d43f39e..b3447cc4 100644 --- a/script/files.lua +++ b/script/files.lua @@ -453,14 +453,14 @@ function m.offset(uri, position) local start = guide.lineRange(lines, row) local offset if start <= 0 or start > #text then - offset = #text + 2 + offset = #text else - offset = utf8.offset(text, position.character + 1, start) or (#text + 2) + offset = utf8.offset(text, position.character + 1, start) or #text end if file._diffInfo then offset = smerger.getOffset(file._diffInfo, offset) end - return offset - 1 + return offset end --- 获取 position 对应的光标位置(根据附近的单词) @@ -482,9 +482,9 @@ function m.offsetOfWord(uri, position) local start = guide.lineRange(lines, row) local offset if start <= 0 or start > #text then - offset = #text + 2 + offset = #text else - offset = utf8.offset(text, position.character + 1, start) or (#text + 2) + offset = utf8.offset(text, position.character + 1, start) or #text end if offset > #text or text:sub(offset-1, offset):match '[%w_][^%w_]' then @@ -493,7 +493,7 @@ function m.offsetOfWord(uri, position) if file._diffInfo then offset = smerger.getOffset(file._diffInfo, offset) end - return offset - 1 + return offset end --- 将应用差异前的offset转换为应用差异后的offset -- cgit v1.2.3