From 96fc7c150f0db6f7eaed3fc4e731210d64581eb8 Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Mon, 11 May 2026 21:54:55 +0200 Subject: [PATCH] fix(api): don't update 'title' when renaming non-curbuf #39743 Problem: 'title' is updated when changing the name of a non-current buffer with nvim_buf_set_name(). Solution: Set RedrawingDisabled when renaming the buffer. --- src/nvim/api/buffer.c | 4 +++- test/functional/ui/title_spec.lua | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 28f30030d5..e62fd0e401 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -965,7 +965,8 @@ void nvim_buf_set_name(Buffer buf, String name, Error *err) const bool is_curbuf = b == curbuf; const int save_acd = p_acd; if (!is_curbuf) { - // Temporarily disable 'autochdir' when setting file name for another buffer. + // Don't update 'title' and 'autochdir' when setting file name for another buffer. + RedrawingDisabled++; p_acd = false; } @@ -976,6 +977,7 @@ void nvim_buf_set_name(Buffer buf, String name, Error *err) aucmd_restbuf(&aco); if (!is_curbuf) { + RedrawingDisabled--; p_acd = save_acd; } }); diff --git a/test/functional/ui/title_spec.lua b/test/functional/ui/title_spec.lua index 37db486abd..876919d43c 100644 --- a/test/functional/ui/title_spec.lua +++ b/test/functional/ui/title_spec.lua @@ -232,5 +232,13 @@ describe('title', function() eq(expected, screen.title) end) end) + + it('changing name of non-current buffer', function() + api.nvim_buf_set_name(buf2, 'foo') + command('redraw!') + screen:expect(function() + eq(expected, screen.title) + end) + end) end) end)