Skip to content

Commit

Permalink
add dot repeatablility to
Browse files Browse the repository at this point in the history
  • Loading branch information
alex.tylor committed Jun 2, 2021
1 parent 704dc44 commit 8a646db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
9 changes: 2 additions & 7 deletions lua/nvim_comment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ function M.operator(mode)
line1 = api.nvim_buf_get_mark(0, "[")[1]
line2 = api.nvim_buf_get_mark(0, "]")[1]
end
-- print("line1", line1, "line2", line2)

M.comment_toggle(line1, line2)
end
Expand Down Expand Up @@ -137,11 +136,7 @@ function M.comment_toggle(line_start, line_end)
end

function M.setup(user_opts)
if user_opts then
for i,v in pairs(user_opts) do
M.config[i] = v
end
end
M.config = vim.tbl_extend('force', M.config, user_opts or {})

-- Messy, change with nvim_exec once merged
vim.api.nvim_command('let g:loaded_text_objects_plugin = 1')
Expand All @@ -157,7 +152,7 @@ function M.setup(user_opts)

if M.config.create_mappings then
local opts = {noremap = true, silent = true}
vim.api.nvim_set_keymap("n", M.config.line_mapping, "<CMD>CommentToggle<CR>", opts)
vim.api.nvim_set_keymap("n", M.config.line_mapping, ":set operatorfunc=CommentOperator<cr>g@", opts)
vim.api.nvim_set_keymap("n", M.config.operator_mapping, ":set operatorfunc=CommentOperator<cr>g@", opts)
vim.api.nvim_set_keymap("v", M.config.operator_mapping, ":<c-u>call CommentOperator(visualmode())<cr>", opts)
end
Expand Down
20 changes: 20 additions & 0 deletions tests/comment_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ end
after_each(function()
end)

it("Should comment/uncomment line with dot repeatable", function()
local expected = [[
-- local function dummy_func()
print("This is a dummy func")
end
local function another_dummy_func()
print("This is a another dummy func")
end
]]

setUpBuffer(input, "lua")
-- comment
runCommandAndAssert(1, "gcl", expected)
-- uncomment
runCommandAndAssert(1, "gcl", input)
-- comment, via dot
runCommandAndAssert(1, ".", expected)
end)

it("Should comment/uncomment via motion and dot", function()
local expected = [[
-- local function dummy_func()
Expand Down

0 comments on commit 8a646db

Please sign in to comment.