summaryrefslogtreecommitdiff
path: root/script/files.lua
diff options
context:
space:
mode:
Diffstat (limited to 'script/files.lua')
-rw-r--r--script/files.lua13
1 files changed, 8 insertions, 5 deletions
diff --git a/script/files.lua b/script/files.lua
index c09cef37..da4b3b70 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -669,9 +669,9 @@ end
--- 将光标位置转化为 position
---@param uri uri
---@param offset integer
----@param isFinish? boolean
+---@param leftOrRight? '"left"'|'"right"'
---@return position
-function m.position(uri, offset, isFinish)
+function m.position(uri, offset, leftOrRight)
local file = m.getFile(uri)
local lines = m.getLines(uri)
local text = m.getText(uri)
@@ -683,7 +683,7 @@ function m.position(uri, offset, isFinish)
end
if file._diffInfo then
local start, finish = smerger.getOffsetBack(file._diffInfo, offset)
- if isFinish then
+ if leftOrRight == 'right' then
offset = finish
else
offset = start
@@ -701,6 +701,9 @@ function m.position(uri, offset, isFinish)
if row < 1 then
row = 1
end
+ if leftOrRight == 'left' then
+ ucol = ucol - 1
+ end
return {
line = row - 1,
character = ucol,
@@ -725,8 +728,8 @@ end
---@param offset2 integer
function m.range(uri, offset1, offset2)
local range = {
- start = m.position(uri, offset1 - 1, false),
- ['end'] = m.position(uri, offset2, true),
+ start = m.position(uri, offset1, 'left'),
+ ['end'] = m.position(uri, offset2, 'right'),
}
return range
end