Skip to content

Commit

Permalink
fix(winbar): keymappings not working anymore (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
gorillamoe authored Aug 14, 2024
1 parent 87bd0e9 commit b158c04
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lua/kulala/globals/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local FS = require("kulala.utils.fs")

local M = {}

M.VERSION = "3.1.1"
M.VERSION = "3.1.2"
M.UI_ID = "kulala://ui"
M.SCRATCHPAD_ID = "kulala://scratchpad"
M.HEADERS_FILE = FS.get_plugin_tmp_dir() .. "/headers.txt"
Expand Down
16 changes: 16 additions & 0 deletions lua/kulala/ui/callbacks.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local M = {}

M.callbacks = {}

M.add = function(name, callback)
if M.callbacks[name] == nil then
M.callbacks[name] = {}
end
table.insert(M.callbacks[name], callback)
end

M.get = function(name)
return M.callbacks[name] or {}
end

return M
7 changes: 6 additions & 1 deletion lua/kulala/ui/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local UICallbacks = require("kulala.ui.callbacks")
local WINBAR = require("kulala.ui.winbar")
local GLOBALS = require("kulala.globals")
local CONFIG = require("kulala.config")
Expand Down Expand Up @@ -42,6 +43,7 @@ end
---This is necessary to prevent bugs like this:
---https://github.com/mistweaverco/kulala.nvim/issues/128
local replace_buffer = function()
local callbacks = UICallbacks.get("on_replace_buffer")
local old_bufnr = get_buffer()

local new_bufnr = vim.api.nvim_create_buf(true, false)
Expand All @@ -60,6 +62,9 @@ local replace_buffer = function()
-- Set the buffer name to the UI_ID after we have deleted the old buffer
vim.api.nvim_buf_set_name(new_bufnr, GLOBALS.UI_ID)

for _, callback in ipairs(callbacks) do
callback(old_bufnr, new_bufnr)
end
return new_bufnr
end

Expand All @@ -68,7 +73,7 @@ local open_buffer = function()
local sd = CONFIG.get().split_direction == "vertical" and "vsplit" or "split"
vim.cmd(sd .. " " .. GLOBALS.UI_ID)
if CONFIG.get().winbar then
WINBAR.create_winbar(get_win(), get_buffer())
WINBAR.create_winbar(get_win())
end
vim.api.nvim_set_current_win(prev_win)
end
Expand Down
8 changes: 5 additions & 3 deletions lua/kulala/ui/winbar.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local UICallbacks = require("kulala.ui.callbacks")
local CONFIG = require("kulala.config")
local M = {}

Expand Down Expand Up @@ -41,13 +42,14 @@ M.toggle_winbar_tab = function(win_id, view)
end

---@param win_id integer|nil Window id
---@param buf integer|nil Buffer
M.create_winbar = function(win_id, buf)
M.create_winbar = function(win_id)
if win_id then
local default_view = CONFIG.get().default_view
M.winbar_sethl()
M.toggle_winbar_tab(win_id, default_view)
M.winbar_set_key_mapping(buf)
UICallbacks.add("on_replace_buffer", function(_, new_buffer)
M.winbar_set_key_mapping(new_buffer)
end)
end
end

Expand Down

0 comments on commit b158c04

Please sign in to comment.