fix(dos): remove incorrect CR

Fixes #875
This commit is contained in:
Lewis Russell 2023-09-23 14:48:46 +01:00 committed by Lewis Russell
parent 664da1fcf3
commit ac922e1785
2 changed files with 10 additions and 4 deletions

View File

@ -69,8 +69,8 @@ function M.run_diff(fa, fb, diff_algo, indent_heuristic, linematch)
run_diff0 = run_diff_xdl
end
local a = vim.tbl_isempty(fa) and '' or table.concat(fa, '\n')
local b = vim.tbl_isempty(fb) and '' or table.concat(fb, '\n')
local a = table.concat(fa, '\n')
local b = table.concat(fb, '\n')
local results = run_diff0(a, b, diff_algo, indent_heuristic, linematch)

View File

@ -49,13 +49,19 @@ function M.buf_lines(bufnr)
-- nvim_buf_get_lines strips carriage returns if fileformat==dos
local buftext = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
if vim.bo[bufnr].fileformat == 'dos' then
for i = 1, #buftext do
local dos = vim.bo[bufnr].fileformat == 'dos'
if dos then
for i = 1, #buftext - 1 do
buftext[i] = buftext[i] .. '\r'
end
end
if vim.bo[bufnr].endofline then
-- Add CR to the last line
if dos then
buftext[#buftext] = buftext[#buftext] .. '\r'
end
buftext[#buftext + 1] = ''
end