File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -1312,8 +1312,9 @@ H.update_buf_diff = vim.schedule_wrap(function(buf_id)
13121312 -- Request highlighting clear to be done in decoration provider
13131313 buf_cache .needs_clear = true
13141314
1315- -- Trigger event for users to possibly hook into
1316- vim .api .nvim_exec_autocmds (' User' , { pattern = ' MiniDiffUpdated' })
1315+ -- Trigger event for users to possibly hook into. Ensure target buffer is
1316+ -- current (for proper `buf` in event data)
1317+ vim .api .nvim_buf_call (buf_id , function () vim .api .nvim_exec_autocmds (' User' , { pattern = ' MiniDiffUpdated' }) end )
13171318
13181319 -- Force redraw. NOTE: Using 'redraw' not always works (`<Cmd>update<CR>`
13191320 -- from keymap with "save" source will not redraw) while 'redraw!' flickers.
Original file line number Diff line number Diff line change @@ -2702,18 +2702,27 @@ T['Diff']['redraws statusline when diff is updated'] = function()
27022702end
27032703
27042704T [' Diff' ][' triggers dedicated event' ] = function ()
2705- child .cmd (' au User MiniDiffUpdated lua _G.n = (_G.n or 0) + 1' )
2705+ child .lua ([[
2706+ _G.event_log = {}
2707+ local track = function(ev) table.insert(_G.event_log, ev.buf) end
2708+ vim.api.nvim_create_autocmd('User', { pattern = 'MiniDiffUpdated', callback = track})
2709+ ]] )
27062710
27072711 set_lines ({ ' aaa' , ' uuu' })
2708- set_ref_text (0 , { ' aaa' })
2709- eq (child .lua_get (' _G.n' ), 1 )
2712+ local buf_id = get_buf ()
2713+
2714+ set_buf (new_buf ())
2715+ set_ref_text (buf_id , { ' aaa' })
2716+ -- Should trigger with correct buffer in event data
2717+ eq (child .lua_get (' _G.event_log' ), { buf_id })
2718+ set_buf (buf_id )
27102719
27112720 set_cursor (2 , 0 )
27122721 type_keys (' o' , ' hello' )
27132722
2714- eq (child .lua_get (' _G.n ' ), 1 )
2723+ eq (child .lua_get (' _G.event_log ' ), { buf_id } )
27152724 sleep (dummy_text_change_delay + small_time )
2716- eq (child .lua_get (' _G.n ' ), 2 )
2725+ eq (child .lua_get (' _G.event_log ' ), { buf_id , buf_id } )
27172726end
27182727
27192728T [' Diff' ][' `MiniDiffUpdated` event can be used to override `minidiff_summary_string` variable' ] = function ()
You can’t perform that action at this time.
0 commit comments