Merge pull request #290 from otavioschwanck/feat/redraw-tabline

feat: redraw tabline
This commit is contained in:
ThePrimeagen 2023-05-28 17:01:40 -06:00 committed by GitHub
commit 21f4c47c68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 6 deletions

View file

@ -11,10 +11,17 @@ local callbacks = {}
-- need one event emitted
local function emit_changed()
log.trace("_emit_changed()")
if harpoon.get_global_settings().save_on_change then
local global_settings = harpoon.get_global_settings()
if global_settings.save_on_change then
harpoon.save()
end
if global_settings.tabline then
vim.cmd("redrawt")
end
if not callbacks["changed"] then
log.trace("_emit_changed(): no callbacks for 'changed', returning")
return

View file

@ -32,14 +32,22 @@ end
function M.setup(opts)
function _G.tabline()
local original_tabs = require('harpoon').get_mark_config().marks
local tabs = shorten_filenames(original_tabs)
local tabs = shorten_filenames(require('harpoon').get_mark_config().marks)
local tabline = ''
for i, tab in ipairs(original_tabs) do
local is_current = string.match(vim.fn.bufname(), tab.filename) or vim.fn.bufname() == tab.filename
local index = require('harpoon.mark').get_index_of(vim.fn.bufname())
local label = tabs[i].filename
for i, tab in ipairs(tabs) do
local is_current = i == index
local label
if tab.filename == "" or tab.filename == "(empty)" then
label = "(empty)"
is_current = false
else
label = tab.filename
end
if is_current then
@ -51,6 +59,7 @@ function M.setup(opts)
end
tabline = tabline .. label .. (opts.tabline_suffix or ' ') .. '%*'
if i < #tabs then
tabline = tabline .. '%T'
end