From 0e0cf68eba3d8f8c790a31427dd34f28e6ddf1f2 Mon Sep 17 00:00:00 2001 From: shadmansaleh <13149513+shadmansaleh@users.noreply.github.com> Date: Mon, 6 Sep 2021 18:14:14 +0600 Subject: [PATCH] Revert: enahce: sync diff&branch component to buffer based of bufnr instead of BufEnter functionally reverted commit 2b90200998af50f8f293d249cc050baf8bdb1cb3 nvim gives first scratch buffer(when opened without a file) and the first opened buffer bufnr 1 . That's why we can't relay completely on bufnr being different to indicate file is different. So back to BufEnter autocommands. closes #38 --- lua/lualine/components/branch.lua | 9 ++++++++- lua/lualine/components/diff.lua | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lua/lualine/components/branch.lua b/lua/lualine/components/branch.lua index fdd9f63..87832e5 100644 --- a/lua/lualine/components/branch.lua +++ b/lua/lualine/components/branch.lua @@ -1,6 +1,9 @@ -- Copyright (c) 2020-2021 shadmansaleh -- MIT license, see LICENSE for more details. local Branch = require('lualine.component'):new() +local modules = require('lualine_require').lazy_require { + utils = 'lualine.utils.utils', +} -- vars Branch.git_branch = '' Branch.git_dir = '' @@ -20,12 +23,16 @@ 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 + modules.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 - -- Sync buffer + -- 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.find_git_dir() end if not is_focused then diff --git a/lua/lualine/components/diff.lua b/lua/lualine/components/diff.lua index c7104b8..20d92ed 100644 --- a/lua/lualine/components/diff.lua +++ b/lua/lualine/components/diff.lua @@ -63,6 +63,7 @@ Diff.new = function(self, options, child) if Diff.diff_checker_enabled then -- setup internal source + modules.utils.define_autocmd('BufEnter', "lua require'lualine.components.diff'.update_diff_args()") modules.utils.define_autocmd('BufWritePost', "lua require'lualine.components.diff'.update_git_diff()") Diff.update_diff_args() end @@ -75,7 +76,9 @@ 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 - -- Sync buffer + -- 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