Skip to content

Commit 8c31df6

Browse files
author
Andrew Ferrier
committed
feat: Make moving to inserted line optional
1 parent 672c89e commit 8c31df6

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

lua/debugprint/init.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local opts
44

55
OPTION_DEFAULTS = {
66
create_keymaps = true,
7+
move_to_debugline = false,
78
filetypes = require("debugprint.filetypes"),
89
}
910

@@ -43,7 +44,10 @@ local indent_line = function(current_line)
4344
local pos = vim.api.nvim_win_get_cursor(0)
4445
-- There's probably a better way to do this indent, but I don't know what it is
4546
vim.cmd(current_line + 1 .. "normal! ==")
46-
vim.api.nvim_win_set_cursor(0, pos)
47+
48+
if not opts.move_to_debugline then
49+
vim.api.nvim_win_set_cursor(0, pos)
50+
end
4751
end
4852

4953
M.debugprint = function(o)

tests/debugprint.lua

+70
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,73 @@ describe("add custom filetype with add_custom_filetypes()", function()
372372
})
373373
end)
374374
end)
375+
376+
describe("move to new line", function()
377+
before_each(function()
378+
vim.api.nvim_set_option_value("expandtab", true, {})
379+
vim.api.nvim_set_option_value("shiftwidth", 4, {})
380+
end)
381+
382+
it("true below", function()
383+
debugprint.setup({move_to_debugline = true})
384+
385+
set_lines({
386+
"foo",
387+
"bar",
388+
})
389+
390+
local filename = write_file("lua")
391+
vim.api.nvim_win_set_cursor(0, { 1, 0 })
392+
feedkeys("dqp")
393+
394+
check_lines({
395+
"foo",
396+
"print('DEBUG[1]: " .. filename .. ":1')",
397+
"bar",
398+
})
399+
400+
assert.are.same(vim.api.nvim_win_get_cursor(0), {2, 0})
401+
end)
402+
403+
it("true above", function()
404+
debugprint.setup({move_to_debugline = true})
405+
406+
set_lines({
407+
"foo",
408+
"bar",
409+
})
410+
411+
local filename = write_file("lua")
412+
vim.api.nvim_win_set_cursor(0, { 1, 0 })
413+
feedkeys("dqP")
414+
415+
check_lines({
416+
"print('DEBUG[1]: " .. filename .. ":1')",
417+
"foo",
418+
"bar",
419+
})
420+
421+
assert.are.same(vim.api.nvim_win_get_cursor(0), {1, 0})
422+
end)
423+
424+
it("false", function()
425+
debugprint.setup({move_to_debugline = false})
426+
427+
set_lines({
428+
"foo",
429+
"bar",
430+
})
431+
432+
local filename = write_file("lua")
433+
vim.api.nvim_win_set_cursor(0, { 1, 0 })
434+
feedkeys("dqp")
435+
436+
check_lines({
437+
"foo",
438+
"print('DEBUG[1]: " .. filename .. ":1')",
439+
"bar",
440+
})
441+
442+
assert.are.same(vim.api.nvim_win_get_cursor(0), {1, 0})
443+
end)
444+
end)

0 commit comments

Comments
 (0)