diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 7096c5fa8a..0c59b8eb67 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -736,6 +736,12 @@ static void clear_diffout(diffout_T *dout) /// @return FAIL for failure. static int diff_write_buffer(buf_T *buf, mmfile_t *m, linenr_T start, linenr_T end) { + if (buf->b_ml.ml_flags & ML_EMPTY) { + m->ptr = NULL; + m->size = 0; + return OK; + } + size_t len = 0; if (end < 0) { diff --git a/test/functional/ui/diff_spec.lua b/test/functional/ui/diff_spec.lua index bad35dd2af..8db6f776d1 100644 --- a/test/functional/ui/diff_spec.lua +++ b/test/functional/ui/diff_spec.lua @@ -614,6 +614,34 @@ int main(int argc, char **argv) ]]) end) + it('Diff empty and non-empty file', function() + write_file(fname, '', false) + write_file(fname_2, 'foo\nbar\nbaz', false) + reread() + + feed(':set diffopt=filler') + screen:expect([[ + {7: }{23:------------------}│{7: }{22:foo }| + {7: }{23:------------------}│{7: }{22:bar }| + {7: }{23:------------------}│{7: }{22:baz }| + {7: }^ │{1:~ }| + {1:~ }│{1:~ }|*10 + {3:') + screen:expect([[ + {7: }{23:------------------}│{7: }{22:foo }| + {7: }{23:------------------}│{7: }{22:bar }| + {7: }{23:------------------}│{7: }{22:baz }| + {7: }^ │{1:~ }| + {1:~ }│{1:~ }|*10 + {3: