Improved conditions a bit

This commit is contained in:
mabubakar
2024-04-26 00:57:36 +05:00
parent c593f4756a
commit febc5ee94b
2 changed files with 5 additions and 3 deletions

View File

@@ -10,7 +10,7 @@ local M = {
---@param bufnr integer
function M.clear_all_ns(bufnr)
if vim.api.nvim_buf_is_valid(bufnr) then
vim.api.nvim_buf_clear_namespace(bufnr, -1, 0, -1)
pcall(function() vim.api.nvim_buf_clear_namespace(bufnr, -1, 0, -1) end)
end
end

View File

@@ -87,7 +87,7 @@ end
---Replace all lines in buffer with given new `lines`
---@param lines string[]
function View:rewrite_lines(lines)
if vim.api.nvim_buf_is_valid(self.buf) then
if self.buf and vim.api.nvim_buf_is_valid(self.buf) then
vim.api.nvim_buf_set_option(self.buf, 'modifiable', true)
vim.api.nvim_buf_set_lines(self.buf, 0, -1, false, lines)
vim.api.nvim_buf_set_option(self.buf, 'modifiable', false)
@@ -95,7 +95,9 @@ function View:rewrite_lines(lines)
end
function View:clear_all_ns()
pcall(function() highlight.clear_all_ns(self.buf) end)
if self.buf then
highlight.clear_all_ns(self.buf)
end
end
---Ensure all existing highlights are already cleared before calling!