From 08b54ba11e29e6df9f83c02539976331617a412c Mon Sep 17 00:00:00 2001 From: Steven Arcangeli Date: Fri, 25 Aug 2023 12:02:59 -0700 Subject: fix: don't modify files when no styling changes --- lua/conform/runner.lua | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lua/conform') diff --git a/lua/conform/runner.lua b/lua/conform/runner.lua index fd806ce..7f11d99 100644 --- a/lua/conform/runner.lua +++ b/lua/conform/runner.lua @@ -37,6 +37,11 @@ local function apply_format(bufnr, original_lines, new_lines) local restore = util.save_win_positions(bufnr) local original_text = table.concat(original_lines, "\n") + -- Trim off the final newline because the original lines won't have it + -- and we want the diffs to agree if the file is unchanged + if new_lines[#new_lines] == "" then + new_lines[#new_lines] = nil + end local new_text = table.concat(new_lines, "\n") local indices = vim.diff(original_text, new_text, { result_type = "indices", -- cgit v1.2.3-70-g09d2