From ac922e178580b65f5cf87914fb214985d8226eaa Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 23 Sep 2023 14:48:46 +0100 Subject: [PATCH] fix(dos): remove incorrect CR Fixes #875 --- lua/gitsigns/diff_int.lua | 4 ++-- lua/gitsigns/util.lua | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lua/gitsigns/diff_int.lua b/lua/gitsigns/diff_int.lua index 9eaf483..2aae862 100644 --- a/lua/gitsigns/diff_int.lua +++ b/lua/gitsigns/diff_int.lua @@ -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) diff --git a/lua/gitsigns/util.lua b/lua/gitsigns/util.lua index 8618673..4bd8eee 100644 --- a/lua/gitsigns/util.lua +++ b/lua/gitsigns/util.lua @@ -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