diff options
-rw-r--r-- | script/text-merger.lua | 6 | ||||
-rw-r--r-- | test/basic/init.lua | 45 |
2 files changed, 48 insertions, 3 deletions
diff --git a/script/text-merger.lua b/script/text-merger.lua index 9e01ba1c..aa124fdd 100644 --- a/script/text-merger.lua +++ b/script/text-merger.lua @@ -46,6 +46,9 @@ local function mergeRows(rows, change) local endChar = change.range['end'].character local insertRows = splitRows(change.text) + local newEndLine = startLine + #insertRows - 1 + local left = getLeft(rows[startLine], startChar) + local right = getRight(rows[endLine], endChar) -- 先把双方的行数调整成一致 local delta = #insertRows - (endLine - startLine + 1) if delta ~= 0 then @@ -58,9 +61,6 @@ local function mergeRows(rows, change) end end -- 先处理第一行和最后一行 - local newEndLine = startLine + #insertRows - 1 - local left = getLeft(rows[startLine], startChar) - local right = getRight(rows[newEndLine], endChar) if startLine == newEndLine then rows[startLine] = left .. insertRows[1] .. right else diff --git a/test/basic/init.lua b/test/basic/init.lua index 5e55c724..a3a11f62 100644 --- a/test/basic/init.lua +++ b/test/basic/init.lua @@ -172,3 +172,48 @@ end text = "p", }, } + +TEST [[ +print(12345) +]] [[ +print(123 +45) +]] { + [1] = { + range = { + ["end"] = { + character = 9, + line = 0, + }, + start = { + character = 9, + line = 0, + }, + }, + rangeLength = 0, + text = "\ +", + }, +} + +TEST [[ +print(123 +45) +]] [[ +print(12345) +]] { + [1] = { + range = { + ["end"] = { + character = 0, + line = 1, + }, + start = { + character = 9, + line = 0, + }, + }, + rangeLength = 2, + text = "", + }, +} |