fix: Properly disable internal diff when source is given

This commit is contained in:
shadmansaleh 2021-08-30 12:03:07 +06:00
parent 114a840a41
commit 0a032cf43e
1 changed files with 15 additions and 12 deletions

View File

@ -105,26 +105,30 @@ Diff.new = function(self, options, child)
} }
end 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 -- setup internal source
utils.define_autocmd('BufEnter', "lua require'lualine.components.diff'.update_diff_args()") utils.define_autocmd('BufEnter', "lua require'lualine.components.diff'.update_diff_args()")
utils.define_autocmd('BufWritePost', "lua require'lualine.components.diff'.update_git_diff()") utils.define_autocmd('BufWritePost', "lua require'lualine.components.diff'.update_git_diff()")
Diff.update_diff_args()
end end
Diff.update_diff_args()
return new_instance return new_instance
end end
-- Function that runs everytime statusline is updated -- Function that runs everytime statusline is updated
Diff.update_status = function(self, is_focused) Diff.update_status = function(self, is_focused)
if Diff.active_bufnr ~= vim.g.actual_curbuf then local git_diff
-- Workaround for https://github.com/hoob3rt/lualine.nvim/issues/286 if Diff.diff_checker_enabled then
-- See upstream issue https://github.com/neovim/neovim/issues/15300 if Diff.active_bufnr ~= vim.g.actual_curbuf then
-- Diff is out of sync re sync it. -- Workaround for https://github.com/hoob3rt/lualine.nvim/issues/286
Diff.update_diff_args() -- See upstream issue https://github.com/neovim/neovim/issues/15300
end -- Diff is out of sync re sync it.
local git_diff = Diff.git_diff Diff.update_diff_args()
if self.options.source then end
git_diff = Diff.git_diff
else
git_diff = self.options.source() git_diff = self.options.source()
end end
@ -167,8 +171,7 @@ end
-- } -- }
-- error_code = { added = -1, modified = -1, removed = -1 } -- error_code = { added = -1, modified = -1, removed = -1 }
function Diff.get_sign_count() function Diff.get_sign_count()
Diff.update_diff_args() if Diff.diff_checker_enabled then Diff.update_diff_args() end
Diff.update_git_diff()
return Diff.git_diff or {added = -1, modified = -1, removed = -1} return Diff.git_diff or {added = -1, modified = -1, removed = -1}
end end