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 -- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details. -- MIT license, see LICENSE for more details.
local utils = require('lualine.utils.utils')
local Branch = require('lualine.component'):new() local Branch = require('lualine.component'):new()
-- vars -- vars
Branch.git_branch = '' Branch.git_branch = ''
@ -21,17 +20,13 @@ Branch.new = function(self, options, child)
end end
-- run watch head on load so branch is present when component is loaded -- run watch head on load so branch is present when component is loaded
Branch.find_git_dir() 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 return new_branch
end end
Branch.update_status = function(_, is_focused) Branch.update_status = function(_, is_focused)
if Branch.active_bufnr ~= vim.g.actual_curbuf then if Branch.active_bufnr ~= vim.g.actual_curbuf then
-- Workaround for https://github.com/hoob3rt/lualine.nvim/issues/286 -- Sync buffer
-- See upstream issue https://github.com/neovim/neovim/issues/15300 Branch.find_git_dir()
-- Diff is out of sync re sync it.
Branch.update_branch()
end end
if not is_focused then return branch_cache[vim.fn.bufnr()] or '' end if not is_focused then return branch_cache[vim.fn.bufnr()] or '' end
return Branch.git_branch return Branch.git_branch

View File

@ -109,7 +109,6 @@ Diff.new = function(self, options, child)
if Diff.diff_checker_enabled then 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('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() Diff.update_diff_args()
end end
@ -122,9 +121,7 @@ Diff.update_status = function(self, is_focused)
local git_diff local git_diff
if Diff.diff_checker_enabled then 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 -- Sync buffer
-- See upstream issue https://github.com/neovim/neovim/issues/15300
-- Diff is out of sync re sync it.
Diff.update_diff_args() Diff.update_diff_args()
end end
git_diff = Diff.git_diff git_diff = Diff.git_diff