From 0a032cf43e0087df98a0b89349ea7846441b96b3 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Mon, 30 Aug 2021 12:03:07 +0600 Subject: [PATCH] fix: Properly disable internal diff when source is given --- lua/lualine/components/diff.lua | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lua/lualine/components/diff.lua b/lua/lualine/components/diff.lua index 97b66ba..6911c38 100644 --- a/lua/lualine/components/diff.lua +++ b/lua/lualine/components/diff.lua @@ -105,26 +105,30 @@ Diff.new = function(self, options, child) } end - if type(new_instance.options.source) ~= 'function' then + Diff.diff_checker_enabled = type(new_instance.options.source) ~= 'function' + + if Diff.diff_checker_enabled then -- setup internal source utils.define_autocmd('BufEnter', "lua require'lualine.components.diff'.update_diff_args()") utils.define_autocmd('BufWritePost', "lua require'lualine.components.diff'.update_git_diff()") + Diff.update_diff_args() end - Diff.update_diff_args() return new_instance end -- Function that runs everytime statusline is updated Diff.update_status = function(self, is_focused) - if Diff.active_bufnr ~= vim.g.actual_curbuf then - -- Workaround for https://github.com/hoob3rt/lualine.nvim/issues/286 - -- See upstream issue https://github.com/neovim/neovim/issues/15300 - -- Diff is out of sync re sync it. - Diff.update_diff_args() - end - local git_diff = Diff.git_diff - if self.options.source then + local git_diff + if Diff.diff_checker_enabled then + if Diff.active_bufnr ~= vim.g.actual_curbuf then + -- Workaround for https://github.com/hoob3rt/lualine.nvim/issues/286 + -- See upstream issue https://github.com/neovim/neovim/issues/15300 + -- Diff is out of sync re sync it. + Diff.update_diff_args() + end + git_diff = Diff.git_diff + else git_diff = self.options.source() end @@ -167,8 +171,7 @@ end -- } -- error_code = { added = -1, modified = -1, removed = -1 } function Diff.get_sign_count() - Diff.update_diff_args() - Diff.update_git_diff() + if Diff.diff_checker_enabled then Diff.update_diff_args() end return Diff.git_diff or {added = -1, modified = -1, removed = -1} end