From 61a81d721ab7f45e40cb0fd4e0b1af695448f710 Mon Sep 17 00:00:00 2001 From: "alex.tylor" Date: Wed, 2 Jun 2021 22:00:04 +0100 Subject: [PATCH] test and readme update for motion count change --- README.md | 1 + lua/nvim_comment.lua | 1 + tests/comment_spec.lua | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/README.md b/README.md index 3710a53..98ab5f9 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Or use the defualt mappings: ** `gcc` comment/uncomment current line ** `gcip` comment/uncomment a paragraph ** `gc4w` comment/uncomment current line +** `gc4l` comment/uncomment 4 lines down, starting with current line ## Configure diff --git a/lua/nvim_comment.lua b/lua/nvim_comment.lua index 6e107ff..b9e3253 100644 --- a/lua/nvim_comment.lua +++ b/lua/nvim_comment.lua @@ -89,6 +89,7 @@ function M.operator(mode) end function M.comment_toggle(line_start, line_end) + line_end = vim.v.count ~= 0 and line_end + vim.v.count - 1 or line_end local left, right = M.get_comment_wrapper() if not left or not right then return end diff --git a/tests/comment_spec.lua b/tests/comment_spec.lua index 3bcbd04..541151e 100644 --- a/tests/comment_spec.lua +++ b/tests/comment_spec.lua @@ -63,6 +63,26 @@ end runCommandAndAssert(1, ".", expected) end) + it("Should comment/uncomment motion with count and dot", 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, "gc2l", expected) + -- uncomment + runCommandAndAssert(1, "gc2l", input) + -- comment, via dot + runCommandAndAssert(1, ".", expected) + end) + it("Should comment out another pararaph via dot", function() local first_expected = [[ -- local function dummy_func()