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()")
end
Diff.update_diff_args() Diff.update_diff_args()
end
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)
local git_diff
if Diff.diff_checker_enabled then
if Diff.active_bufnr ~= vim.g.actual_curbuf then if Diff.active_bufnr ~= vim.g.actual_curbuf then
-- Workaround for https://github.com/hoob3rt/lualine.nvim/issues/286 -- Workaround for https://github.com/hoob3rt/lualine.nvim/issues/286
-- See upstream issue https://github.com/neovim/neovim/issues/15300 -- See upstream issue https://github.com/neovim/neovim/issues/15300
-- Diff is out of sync re sync it. -- Diff is out of sync re sync it.
Diff.update_diff_args() Diff.update_diff_args()
end end
local git_diff = Diff.git_diff git_diff = Diff.git_diff
if self.options.source then 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