Skip to content

Commit

Permalink
fix: properly check for null buffer loading state on review open
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeLagrange committed Feb 5, 2025
1 parent d668d80 commit 28d1ff2
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions lua/octo/reviews/file-entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -497,19 +497,28 @@ end
function M._get_null_buffer()
local msg = "Loading ..."
local bn = M._null_buffer[msg]
if not bn or vim.api.nvim_buf_is_loaded(bn) then
local nbn = vim.api.nvim_create_buf(false, false)
vim.api.nvim_buf_set_lines(nbn, 0, -1, false, { msg })
local bufname = utils.path_join { "octo", "null" }
vim.api.nvim_buf_set_option(nbn, "modified", false)
vim.api.nvim_buf_set_option(nbn, "modifiable", false)
local ok = pcall(vim.api.nvim_buf_set_name, nbn, bufname)
if not ok then
utils.wipe_named_buffer(bufname)
vim.api.nvim_buf_set_name(nbn, bufname)
end
M._null_buffer[msg] = nbn

if bn and vim.api.nvim_buf_is_valid(bn) then
-- Null buffer already exists and is loaded
return bn
end

-- Create the null buffer
local nbn = vim.api.nvim_create_buf(false, false)

vim.api.nvim_buf_set_lines(nbn, 0, -1, false, { msg })
local bufname = utils.path_join { "octo", "null" }
vim.api.nvim_buf_set_option(nbn, "modified", false)
vim.api.nvim_buf_set_option(nbn, "modifiable", false)

local ok = pcall(vim.api.nvim_buf_set_name, nbn, bufname)
if not ok then
utils.wipe_named_buffer(bufname)
vim.api.nvim_buf_set_name(nbn, bufname)
end

M._null_buffer[msg] = nbn

return M._null_buffer[msg]
end

Expand Down

0 comments on commit 28d1ff2

Please sign in to comment.