Skip to content

Commit 6a08653

Browse files
committed
fix: get insert mode variable working with noice - closes #86
1 parent b97bd8a commit 6a08653

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

lua/debugprint/setup.lua

+15-8
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ local map_key = function(mode, lhs, opts)
1313
end
1414

1515
---@param keys string?
16+
---@param insert_mode boolean
1617
---@return nil
17-
local feedkeys = function(keys)
18+
local feedkeys = function(keys, insert_mode)
1819
if keys ~= nil and keys ~= "" then
19-
vim.api.nvim_feedkeys(keys, "xt", true)
20+
if insert_mode then
21+
vim.api.nvim_put({ keys }, "c", true, true)
22+
else
23+
vim.api.nvim_feedkeys(keys, "xt", true)
24+
end
2025
end
2126
end
2227

@@ -104,13 +109,15 @@ M.map_keys_and_commands = function(global_opts)
104109

105110
map_key("i", global_opts.keymaps.insert.variable, {
106111
callback = function()
107-
return debugprint.debugprint({
108-
insert = true,
109-
variable = true,
110-
ignore_treesitter = true,
111-
})
112+
feedkeys(
113+
debugprint.debugprint({
114+
insert = true,
115+
variable = true,
116+
ignore_treesitter = true,
117+
}),
118+
true
119+
)
112120
end,
113-
expr = true,
114121
desc = "Variable debug in-place (always prompt)",
115122
})
116123

tests/debugprint.lua

+19
Original file line numberDiff line numberDiff line change
@@ -2456,6 +2456,25 @@ describe("can support insert mode", function()
24562456
})
24572457
end)
24582458

2459+
it("can insert a variable statement below - indented", function()
2460+
assert.equals(notify_message, nil)
2461+
2462+
local filename = init_file({
2463+
" foo",
2464+
" bar",
2465+
}, "lua", 1, 0)
2466+
2467+
feedkeys("o<C-G>vwibble<CR>")
2468+
2469+
check_lines({
2470+
" foo",
2471+
" print('DEBUGPRINT[1]: "
2472+
.. filename
2473+
.. ":2: wibble=' .. vim.inspect(wibble))",
2474+
" bar",
2475+
})
2476+
end)
2477+
24592478
it("don't insert when skipping variable name", function()
24602479
assert.equals(notify_message, nil)
24612480

0 commit comments

Comments
 (0)