Skip to content

Commit fe8976c

Browse files
committed
fix(hijack): simplify callback execution logic
Ref: #30
1 parent f9099a9 commit fe8976c

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

lua/tiny-glimmer/hijack.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ end
3434
---@param map string The key mapping to hijack
3535
---@param original_mapping table The original mapping details
3636
---@param command string|function|nil Additional command to execute
37-
function M.hijack(mode, lhs, rhs, original_mapping, command)
37+
function M.hijack(mode, lhs, rhs, command)
3838
mode = mode:gsub("%s+", "")
3939
if mode == nil or mode == "" then
4040
mode = "n"
@@ -47,13 +47,16 @@ function M.hijack(mode, lhs, rhs, original_mapping, command)
4747
end
4848

4949
if existing_mapping and existing_mapping.callback then
50+
print("existing_mapping.callback")
5051
for _ = 1, vim.v.count1 do
5152
existing_mapping.callback()
5253
end
5354
elseif existing_mapping and existing_mapping.rhs then
55+
print("existing_mapping.rhs")
5456
vim.api.nvim_feedkeys(add_count_and_registers(existing_mapping.rhs), "n", true)
5557
else
5658
vim.api.nvim_feedkeys(add_count_and_registers(lhs), "n", true)
59+
print("vim.api.nvim_feedkeys(add_count_and_registers(lhs), 'n', true)")
5760
end
5861
end, {
5962
noremap = true,

lua/tiny-glimmer/init.lua

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ M.config = {
175175
virt_text = {
176176
priority = 2048,
177177
},
178-
hijack_ft_disabled = {
179-
"alpha",
180-
"snacks_dashboard",
181-
},
182178
}
183179

184180
-- Helper Functions
@@ -280,8 +276,7 @@ function M.custom_remap(map, mode, callback)
280276
end
281277
end
282278

283-
local original_mapping = vim.fn.maparg(lhs, mode, false, true)
284-
require("tiny-glimmer.hijack").hijack(mode, lhs, rhs, original_mapping, callback)
279+
require("tiny-glimmer.hijack").hijack(mode, lhs, rhs, callback)
285280
end
286281

287282
local function setup_hijacks()
@@ -363,24 +358,8 @@ function M.setup(options)
363358

364359
AnimationFactory.initialize(M.config, effects_pool, M.config.refresh_interval_ms)
365360

366-
vim.schedule(function()
367-
setup_hijacks()
368-
end)
369-
370-
vim.api.nvim_create_autocmd("BufEnter", {
371-
callback = function(event)
372-
if hijack_done then
373-
return
374-
end
361+
setup_hijacks()
375362

376-
if vim.tbl_contains(M.config.hijack_ft_disabled, vim.bo.filetype) then
377-
return
378-
end
379-
380-
setup_hijacks()
381-
hijack_done = true
382-
end,
383-
})
384363
vim.api.nvim_create_autocmd({ "BufEnter", "BufLeave" }, {
385364
group = animation_group,
386365
callback = function()

0 commit comments

Comments
 (0)