From 132bbd1cbd490a65bc186c4a9f449c6d2f0a7666 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 28 Aug 2023 12:36:00 +0200 Subject: [PATCH] fix(api): handle clearing out last line of non-current buffer fixes #24911 --- src/nvim/memline.c | 2 +- test/functional/api/buffer_spec.lua | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/nvim/memline.c b/src/nvim/memline.c index b100942594..5839061aac 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -2523,7 +2523,7 @@ static int ml_delete_int(buf_T *buf, linenr_T lnum, bool message) set_keep_msg(_(no_lines_msg), 0); } - int i = ml_replace(1, "", true); + int i = ml_replace_buf(buf, 1, "", true); buf->b_ml.ml_flags |= ML_EMPTY; return i; diff --git a/test/functional/api/buffer_spec.lua b/test/functional/api/buffer_spec.lua index 0afe619b03..73a8749682 100644 --- a/test/functional/api/buffer_spec.lua +++ b/test/functional/api/buffer_spec.lua @@ -279,6 +279,18 @@ describe('api/buf', function() ]]} end) end) + + it('handles clearing out non-current buffer #24911', function() + local buf = meths.get_current_buf() + meths.buf_set_lines(buf, 0, -1, true, {"aaa", "bbb", "ccc"}) + command("new") + + meths.buf_set_lines(0, 0, -1, true, {"xxx", "yyy", "zzz"}) + + meths.buf_set_lines(buf, 0, -1, true, {}) + eq({"xxx", "yyy", "zzz"}, meths.buf_get_lines(0, 0, -1, true)) + eq({''}, meths.buf_get_lines(buf, 0, -1, true)) + end) end) describe('deprecated: {get,set,del}_line', function()