Merge pull request #66 from m-abubakar/fix_error_on_close

Fix #65 Error on closing outline when computer is running slow
This commit is contained in:
~hedy
2025-02-23 22:28:27 +08:00
committed by GitHub
2 changed files with 14 additions and 6 deletions

View File

@@ -9,13 +9,17 @@ local M = {
---Clear all highlights in buffer
---@param bufnr integer
function M.clear_all_ns(bufnr)
vim.api.nvim_buf_clear_namespace(bufnr, -1, 0, -1)
if vim.api.nvim_buf_is_valid(bufnr) then
pcall(function() vim.api.nvim_buf_clear_namespace(bufnr, -1, 0, -1) end)
end
end
---Clear hover highlights in buffer
---@param bufnr integer
function M.clear_hovers(bufnr)
if vim.api.nvim_buf_is_valid(bufnr) then
vim.api.nvim_buf_clear_namespace(bufnr, M.ns.hover, 0, -1)
end
end
---Add single hover highlights

View File

@@ -99,13 +99,17 @@ end
---Replace all lines in buffer with given new `lines`
---@param lines string[]
function View:rewrite_lines(lines)
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)
end
end
function View:clear_all_ns()
if self.buf then
highlight.clear_all_ns(self.buf)
end
end
---Ensure all existing highlights are already cleared before calling!