From 9828b5e6e0c513dc20f756db1350aa6e38faa5b7 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, 11 Mar 2021 21:12:08 +0800 Subject: some fix --- script/text-merger.lua | 6 +++--- 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 = "", + }, +} -- cgit v1.2.3