Skip to content

Commit

Permalink
Fix issue where using leader in mapping and leader is a space
Browse files Browse the repository at this point in the history
  • Loading branch information
alex.tylor committed Jun 3, 2021
1 parent fca3189 commit a228f1d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lua/nvim_comment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,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, ":normal " .. M.config.operator_mapping .. "l<CR>", opts)
vim.api.nvim_set_keymap("n", M.config.line_mapping, ":set operatorfunc=CommentOperator<cr>g@l", 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
47 changes: 47 additions & 0 deletions tests/comment_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,53 @@ describe('padding flag', function()
end)
end)

describe('mapping with leader as space', function()

local input = [[
<note>
<to>Tove</to>
<from>Jani</from>
</note>
]]

it("Should toggle comment with line mapping", function()
require('nvim_comment').setup({
line_mapping = " cc",
operator_mapping = " c"
})

local expected = [[
<note>
<to>Tove</to>
<!--<from>Jani</from>-->
</note>
]]

setUpBuffer(input, "xml")
-- comment
runCommandAndAssert(3, " cc", expected)
end)

it("Should toggle comment with operator mapping", function()
require('nvim_comment').setup({
line_mapping = " cc",
operator_mapping = " c"
})

local expected = [[
<note>
<to>Tove</to>
<!-- <from>Jani</from>-->
<!--</note>-->
]]

setUpBuffer(input, "xml")
-- comment
runCommandAndAssert(3, " c1j", expected)
end)

end)

describe('comment empty flag', function()

local input = [[
Expand Down

0 comments on commit a228f1d

Please sign in to comment.