Skip to content

Commit

Permalink
fix: clear images that were not rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd committed Oct 29, 2023
1 parent 1650ecc commit c91d47c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
20 changes: 11 additions & 9 deletions lua/image/backends/kitty/init.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local utils = require("image/utils")
local codes = require("image/backends/kitty/codes")
local helpers = require("image/backends/kitty/helpers")
local utils = require("image/utils")

local editor_tty = utils.term.get_tty()

Expand Down Expand Up @@ -151,15 +151,17 @@ backend.clear = function(image_id, shallow)
if image_id then
local image = backend.state.images[image_id]
if not image then return end
if not image.is_rendered then return end

helpers.write_graphics({
action = codes.control.action.delete,
display_delete = "i",
image_id = image.internal_id,
quiet = 2,
tty = get_clear_tty_override(),
})
if image.is_rendered then
helpers.write_graphics({
action = codes.control.action.delete,
display_delete = "i",
image_id = image.internal_id,
quiet = 2,
tty = get_clear_tty_override(),
})
end

image.is_rendered = false
if not shallow then
backend.state.images[image_id] = nil
Expand Down
10 changes: 2 additions & 8 deletions lua/image/utils/document.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ local create_document_integration = function(config)
local render = vim.schedule_wrap(
---@param ctx IntegrationContext
function(ctx)
local windows = utils.window.get_windows({
normal = true,
with_masks = ctx.state.options.window_overlap_clear_enabled,
ignore_masking_filetypes = ctx.state.options.window_overlap_clear_ft_ignore,
})
local windows = utils.window.get_windows({ normal = true })

local image_queue = {}

Expand Down Expand Up @@ -119,9 +115,7 @@ local create_document_integration = function(config)
if vim.tbl_contains(text_change_watched_buffers, buffer) then return end
vim.api.nvim_buf_attach(buffer, false, {
on_lines = function()
vim.schedule(function()
render(ctx)
end)
render(ctx)
end,
})
table.insert(text_change_watched_buffers, buffer)
Expand Down

0 comments on commit c91d47c

Please sign in to comment.