enahce: sync diff&branch component to buffer based of bufnr instead of BufEnter

This commit is contained in:
shadmansaleh 2021-08-30 12:17:22 +06:00
parent 0a032cf43e
commit 2b90200998
2 changed files with 3 additions and 11 deletions

View File

@ -1,6 +1,5 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local utils = require('lualine.utils.utils')
local Branch = require('lualine.component'):new()
-- vars
Branch.git_branch = ''
@ -21,17 +20,13 @@ Branch.new = function(self, options, child)
end
-- run watch head on load so branch is present when component is loaded
Branch.find_git_dir()
-- update branch state of BufEnter as different Buffer may be on different repos
utils.define_autocmd('BufEnter', "lua require'lualine.components.branch'.find_git_dir()")
return new_branch
end
Branch.update_status = function(_, is_focused)
if Branch.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.
Branch.update_branch()
-- Sync buffer
Branch.find_git_dir()
end
if not is_focused then return branch_cache[vim.fn.bufnr()] or '' end
return Branch.git_branch

View File

@ -109,7 +109,6 @@ Diff.new = function(self, options, child)
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
@ -122,9 +121,7 @@ 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
-- 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.
-- Sync buffer
Diff.update_diff_args()
end
git_diff = Diff.git_diff