Revert "Fix #14: better active window detection"
This reverts commit 680cfeb074.
This commit is contained in:
@@ -98,9 +98,9 @@ local function remove_hidden_sections(sections)
|
||||
end
|
||||
|
||||
-------------------- SECTION HIGHLIGHTING ------------------
|
||||
local function get_section_state(section, active)
|
||||
local function get_section_state(section)
|
||||
if section.class == 'mode' then
|
||||
if active then
|
||||
if common.is_active() then
|
||||
local mode = common.modes[fn.mode()] or common.modes['?']
|
||||
return mode.state
|
||||
end
|
||||
@@ -115,35 +115,40 @@ local function get_section_state(section, active)
|
||||
end
|
||||
return state
|
||||
end
|
||||
return active and 'active' or 'inactive'
|
||||
return common.is_active() and 'active' or 'inactive'
|
||||
end
|
||||
|
||||
local function highlight_sections(sections, active)
|
||||
local highlight_section = function(section)
|
||||
if type(section) ~= 'table' then
|
||||
return section
|
||||
end
|
||||
if section.class == 'none' then
|
||||
return section.item
|
||||
end
|
||||
local state = get_section_state(section, active)
|
||||
local hlgroup = fmt('Hardline_%s_%s', section.class, state)
|
||||
if fn.hlexists(hlgroup) == 0 then
|
||||
return section.item
|
||||
end
|
||||
return fmt('%%#%s#%s%%*', hlgroup, section.item)
|
||||
local function highlight_section(section)
|
||||
if type(section) ~= 'table' then
|
||||
return section
|
||||
end
|
||||
if section.class == 'none' then
|
||||
return section.item
|
||||
end
|
||||
local state = get_section_state(section)
|
||||
local hlgroup = fmt('Hardline_%s_%s', section.class, state)
|
||||
if fn.hlexists(hlgroup) == 0 then
|
||||
return section.item
|
||||
end
|
||||
return fmt('%%#%s#%s%%*', hlgroup, section.item)
|
||||
end
|
||||
|
||||
local function highlight_sections(sections)
|
||||
return vim.tbl_map(highlight_section, sections)
|
||||
end
|
||||
|
||||
-------------------- STATUSLINE ----------------------------
|
||||
function M.update_statusline(active)
|
||||
sections = M.options.sections
|
||||
sections = remove_hidden_sections(sections)
|
||||
sections = load_sections(sections)
|
||||
sections = remove_empty_sections(sections)
|
||||
sections = aggregate_sections(sections)
|
||||
return table.concat(highlight_sections(sections, active))
|
||||
function M.update_statusline()
|
||||
local sections = cache.previous
|
||||
if common.is_active() or not sections then
|
||||
sections = M.options.sections
|
||||
sections = remove_hidden_sections(sections)
|
||||
sections = load_sections(sections)
|
||||
sections = remove_empty_sections(sections)
|
||||
sections = aggregate_sections(sections)
|
||||
cache.previous, cache.current = cache.current, sections
|
||||
end
|
||||
return table.concat(highlight_sections(sections))
|
||||
end
|
||||
|
||||
-------------------- BUFFERLINE ----------------------------
|
||||
@@ -186,7 +191,8 @@ end
|
||||
|
||||
local function set_statusline()
|
||||
o.showmode = false
|
||||
o.statusline = [[%!luaeval('require("hardline").update_statusline(true)')]]
|
||||
o.statusline = [[%!luaeval('require("hardline").update_statusline()')]]
|
||||
wo.statusline = o.statusline
|
||||
end
|
||||
|
||||
local function set_bufferline()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local cmd = vim.cmd
|
||||
local cmd, fn = vim.cmd, vim.fn
|
||||
local g = vim.g
|
||||
local fmt = string.format
|
||||
local M = {}
|
||||
|
||||
@@ -23,6 +24,10 @@ function M.echo(hlgroup, msg)
|
||||
cmd('echohl None')
|
||||
end
|
||||
|
||||
function M.is_active()
|
||||
return g.statusline_winid == fn.win_getid()
|
||||
end
|
||||
|
||||
function M.set_cache_autocmds(augroup)
|
||||
cmd(fmt('augroup %s', augroup))
|
||||
cmd('autocmd!')
|
||||
|
||||
@@ -7,17 +7,3 @@ if exists('g:loaded_hardline')
|
||||
endif
|
||||
|
||||
let g:loaded_hardline = 1
|
||||
|
||||
function! ActiveLine()
|
||||
return luaeval('require("hardline").update_statusline(true)')
|
||||
endfunction
|
||||
|
||||
function! InactiveLine()
|
||||
return luaeval('require("hardline").update_statusline(false)')
|
||||
endfunction
|
||||
|
||||
augroup hardline
|
||||
autocmd!
|
||||
autocmd WinEnter,BufEnter * setlocal statusline=%!ActiveLine()
|
||||
autocmd WinLeave,BufLeave * setlocal statusline=%!InactiveLine()
|
||||
augroup END
|
||||
|
||||
Reference in New Issue
Block a user