From 67004277b8b0ce5d1dc9cce54edf2302cea1e057 Mon Sep 17 00:00:00 2001 From: Javier Ugarte Date: Fri, 2 Aug 2024 09:54:25 -0300 Subject: [PATCH] fix: "Failed to rename buffer" when trying to reopen the result buffer in split mode after having closed it manually --- lua/hurl/split.lua | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lua/hurl/split.lua b/lua/hurl/split.lua index a23039b..7bcb71e 100644 --- a/lua/hurl/split.lua +++ b/lua/hurl/split.lua @@ -17,6 +17,12 @@ local M = {} --- - headers table ---@param type 'json' | 'html' | 'xml' | 'text' M.show = function(data, type) + local function quit() + -- set buffer name to empty string so it wouldn't conflict when next time buffer opened + vim.api.nvim_buf_set_name(split.bufnr, '') + vim.cmd('q') + split:unmount() + end -- mount/open the component split:mount() @@ -29,7 +35,8 @@ M.show = function(data, type) if _HURL_GLOBAL_CONFIG.auto_close then -- unmount component when buffer is closed split:on(event.BufLeave, function() - split:unmount() + quit() + -- split:unmount() end) end @@ -75,12 +82,6 @@ M.show = function(data, type) vim.api.nvim_feedkeys('zx', 'n', true) end, 200) - local function quit() - -- set buffer name to empty string so it wouldn't conflict when next time buffer opened - vim.api.nvim_buf_set_name(split.bufnr, '') - vim.cmd('q') - split:unmount() - end split:map('n', _HURL_GLOBAL_CONFIG.mappings.close, function() quit() end)