Skip to content

Commit

Permalink
feat(on_click): allow callback to be a string.
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelot committed May 25, 2022
1 parent 1d69aa8 commit 14779d6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lua/heirline/statusline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,19 @@ function StatusLine:get_win_attr(attr, default)
end

local function register_global_function(component, on_click)
if type(on_click.callback) == "string" then
return on_click.callback
end

local func_name = type(on_click.name) == "function" and on_click.name(component) or on_click.name
if _G[func_name] and not on_click.update then
return func_name
return "v:lua." .. func_name
end

_G[func_name] = function(minwid, nclicks, button)
on_click.callback(component, minwid, nclicks, button)
end
return func_name
return "v:lua." .. func_name
end

function StatusLine:eval()
Expand All @@ -146,7 +151,7 @@ function StatusLine:eval()

if self.on_click then
local func_name = register_global_function(self, self.on_click)
table.insert(stl, "%@v:lua." .. func_name .. "@")
table.insert(stl, "%@" .. func_name .. "@")
end

if self.provider then
Expand All @@ -155,7 +160,6 @@ function StatusLine:eval()
table.insert(stl, hl_str_start .. provider_str .. hl_str_end)
end


local children_i
if self.pick_child then
children_i = self.pick_child
Expand Down

0 comments on commit 14779d6

Please sign in to comment.