From 2667904fb0ee62832c55b56acb9ade3e02a0c202 Mon Sep 17 00:00:00 2001 From: Artem Vasenin Date: Tue, 13 Aug 2024 00:08:12 +0100 Subject: [PATCH] feat(blame_line): add option to show when not focused --- README.md | 1 + doc/gitsigns.txt | 6 +++++- lua/gitsigns/config.lua | 4 ++++ lua/gitsigns/current_line_blame.lua | 13 +++++++++---- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c1ec0ca..c22b4d6 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ require('gitsigns').setup { delay = 1000, ignore_whitespace = false, virt_text_priority = 100, + use_focus = true, }, current_line_blame_formatter = ', - ', sign_priority = 6, diff --git a/doc/gitsigns.txt b/doc/gitsigns.txt index 1e6d35b..2a4f56e 100644 --- a/doc/gitsigns.txt +++ b/doc/gitsigns.txt @@ -67,6 +67,7 @@ of the default settings: delay = 1000, ignore_whitespace = false, virt_text_priority = 100, + use_focus = true, }, current_line_blame_formatter = ', - ', sign_priority = 6, @@ -823,7 +824,8 @@ current_line_blame_opts *gitsigns-config-current_line_blame_opts* delay = 1000, virt_text = true, virt_text_pos = "eol", - virt_text_priority = 100 + virt_text_priority = 100, + use_focus = true, }` < Options for the current line blame annotation. @@ -844,6 +846,8 @@ current_line_blame_opts *gitsigns-config-current_line_blame_opts* Ignore whitespace when running blame. • virt_text_priority: integer Priority of virtual text. + • use_focus: boolean + Enable only when buffer is in focus • extra_opts: string[] Extra options passed to `git-blame`. diff --git a/lua/gitsigns/config.lua b/lua/gitsigns/config.lua index 0d92a71..622cd8c 100644 --- a/lua/gitsigns/config.lua +++ b/lua/gitsigns/config.lua @@ -42,6 +42,7 @@ --- @field virt_text_pos? 'eol'|'overlay'|'right_align' --- @field delay? integer --- @field virt_text_priority? integer +--- @field use_focus? boolean --- @class (exact) Gitsigns.BlameOpts --- @field ignore_whitespace? boolean @@ -680,6 +681,7 @@ M.schema = { virt_text_pos = 'eol', virt_text_priority = 100, delay = 1000, + use_focus = true, }, description = [[ Options for the current line blame annotation. @@ -700,6 +702,8 @@ M.schema = { Ignore whitespace when running blame. • virt_text_priority: integer Priority of virtual text. + • use_focus: boolean + Enable only when buffer is in focus • extra_opts: string[] Extra options passed to `git-blame`. ]], diff --git a/lua/gitsigns/current_line_blame.lua b/lua/gitsigns/current_line_blame.lua index 1f56454..94b0b55 100644 --- a/lua/gitsigns/current_line_blame.lua +++ b/lua/gitsigns/current_line_blame.lua @@ -225,13 +225,18 @@ function M.setup() -- show current buffer line blame immediately M.update(api.nvim_get_current_buf()) - local events = { 'FocusGained', 'BufEnter', 'CursorMoved', 'CursorMovedI' } + local update_events = { 'BufEnter', 'CursorMoved', 'CursorMovedI' } + local reset_events = { 'InsertEnter', 'BufLeave' } if vim.fn.exists('#WinResized') == 1 then -- For nvim 0.9+ - events[#events + 1] = 'WinResized' + update_events[#update_events + 1] = 'WinResized' + end + if opts.use_focus then + update_events[#update_events + 1] = 'FocusGained' + reset_events[#reset_events + 1] = 'FocusLost' end - api.nvim_create_autocmd(events, { + api.nvim_create_autocmd(update_events, { group = group, callback = function(args) reset(args.buf) @@ -239,7 +244,7 @@ function M.setup() end, }) - api.nvim_create_autocmd({ 'InsertEnter', 'FocusLost', 'BufLeave' }, { + api.nvim_create_autocmd(reset_events, { group = group, callback = function(args) reset(args.buf)