@@ -53,6 +53,7 @@ local state = {
5353 tmp_dir = vim .fn .tempname (),
5454 disable_decorator_handling = false ,
5555 hijacked_win_buf_images = {},
56+ enabled = true ,
5657}
5758
5859--- @type API
@@ -102,6 +103,9 @@ api.setup = function(options)
102103 local window_history = {}
103104 vim .api .nvim_set_decoration_provider (state .extmarks_namespace , {
104105 on_win = function (_ , winid , bufnr , topline , botline )
106+ -- bail if not enabled
107+ if not state .enabled then return false end
108+
105109 -- bail if decorator handling is disabled
106110 if state .disable_decorator_handling then return false end
107111
@@ -208,6 +212,9 @@ api.setup = function(options)
208212 vim .api .nvim_create_autocmd ({ " BufLeave" , " WinClosed" , " TabEnter" }, {
209213 group = group ,
210214 callback = function () -- auto-clear images when windows and buffers change
215+ -- bail if not enabled
216+ if not state .enabled then return end
217+
211218 vim .schedule (function ()
212219 local images = api .get_images ()
213220
@@ -251,6 +258,9 @@ api.setup = function(options)
251258 vim .api .nvim_create_autocmd ({ " WinScrolled" }, {
252259 group = group ,
253260 callback = function (au )
261+ -- bail if not enabled
262+ if not state .enabled then return end
263+
254264 local images = api .get_images ({ window = tonumber (au .file ) })
255265 for _ , current_image in ipairs (images ) do
256266 current_image :render ()
@@ -262,6 +272,9 @@ api.setup = function(options)
262272 vim .api .nvim_create_autocmd ({ " WinResized" }, {
263273 group = group ,
264274 callback = function ()
275+ -- bail if not enabled
276+ if not state .enabled then return end
277+
265278 local images = api .get_images ()
266279 for _ , current_image in ipairs (images ) do
267280 if current_image .window ~= nil then current_image :render () end
@@ -303,9 +316,11 @@ api.setup = function(options)
303316 vim .api .nvim_create_autocmd (" FocusLost" , {
304317 group = group ,
305318 callback = function () -- auto-clear images when windows and buffers change
319+ -- bail if not enabled
320+ if not state .enabled then return end
321+
306322 vim .schedule (function ()
307323 -- utils.debug("FocusLost")
308-
309324 if
310325 state .options .editor_only_render_when_focused
311326 or (utils .tmux .is_tmux and utils .tmux .get_window_id () ~= initial_tmux_window_id )
@@ -328,6 +343,9 @@ api.setup = function(options)
328343 vim .api .nvim_create_autocmd (" FocusGained" , {
329344 group = group ,
330345 callback = function () -- auto-clear images when windows and buffers change
346+ -- bail if not enabled
347+ if not state .enabled then return end
348+
331349 -- utils.debug("FocusGained")
332350
333351 state .disable_decorator_handling = false
@@ -362,6 +380,9 @@ api.setup = function(options)
362380 group = group ,
363381 pattern = state .options .hijack_file_patterns ,
364382 callback = function (event )
383+ -- bail if not enabled
384+ if not state .enabled then return end
385+
365386 local buf = event .buf
366387 local win = vim .api .nvim_get_current_win ()
367388 local path = vim .api .nvim_buf_get_name (buf )
@@ -375,6 +396,9 @@ api.setup = function(options)
375396 vim .api .nvim_create_autocmd ({ " BufWritePost" , " TextChanged" , " TextChangedI" , " InsertEnter" }, {
376397 group = group ,
377398 callback = function (event )
399+ -- bail if not enabled
400+ if not state .enabled then return end
401+
378402 local images = api .get_images ({ buffer = event .buf })
379403 for _ , img in ipairs (images ) do
380404 local has_moved , extmark_y , extmark_x = img :has_extmark_moved ()
@@ -492,4 +516,25 @@ api.create_report = function()
492516 return report .create (state )
493517end
494518
519+ --- @return boolean
520+ api .is_enabled = function ()
521+ return state .enabled
522+ end
523+
524+ api .enable = function ()
525+ state .enabled = true
526+ local images = api .get_images ()
527+ for _ , current_image in ipairs (images ) do
528+ current_image :render ()
529+ end
530+ end
531+
532+ api .disable = function ()
533+ state .enabled = false
534+ local images = api .get_images ()
535+ for _ , current_image in ipairs (images ) do
536+ current_image :clear (true )
537+ end
538+ end
539+
495540return api
0 commit comments