From ca3fcec66c19961001abf30ae01cc1fa43d0f058 Mon Sep 17 00:00:00 2001 From: arne314 <73391160+arne314@users.noreply.github.com> Date: Wed, 19 Mar 2025 13:10:44 +0100 Subject: [PATCH] fix(anki): reload nvim buffer on anki id update --- lua/typstar/anki.lua | 5 ++++- lua/typstar/utils.lua | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lua/typstar/anki.lua b/lua/typstar/anki.lua index 9dfa6e6..06f56a3 100644 --- a/lua/typstar/anki.lua +++ b/lua/typstar/anki.lua @@ -17,7 +17,10 @@ local function run_typstar_anki(args) anki_key, args ) - utils.run_shell_command(cmd, true) + local handle_output = function(msg) + if string.match(msg, 'Done') then vim.cmd('checktime') end + end + utils.run_shell_command(cmd, true, handle_output) end function M.scan() run_typstar_anki('') end diff --git a/lua/typstar/utils.lua b/lua/typstar/utils.lua index 85bc145..6dccdae 100644 --- a/lua/typstar/utils.lua +++ b/lua/typstar/utils.lua @@ -26,10 +26,12 @@ function M.insert_text_block(snip) vim.api.nvim_buf_set_lines(vim.api.nvim_get_current_buf(), line_num, line_num, false, lines) end -function M.run_shell_command(cmd, show_output) +function M.run_shell_command(cmd, show_output, extra_handler) + extra_handler = extra_handler or function(msg) end local handle_output = function(data, err) local msg = table.concat(data, '\n') if not string.match(msg, '^%s*$') then + extra_handler(msg) local level = err and vim.log.levels.ERROR or vim.log.levels.INFO vim.notify(msg, level) end