Skip to content

Commit e42e290

Browse files
authored
fix: respect updated v:count when using . repeat (#253)
Previously, when you press `3gcc` 3 lines will be (un)commented then pressing `.` also (un)comments 3 lines. This is fine. But if you press `4.` (prefixing the `.` with a `count`) it (un)comments 3 lines instead of 4 which is wrong. As `.` repeat should respect the updated value of the `v:count`, in this case, `4` should be used instead of `3`. With this PR, `.` will respect the updated value of `v:count` by removing an old workaround. This PR also replaces `vim.v.count` with `vim.api.nvim_get_vvar('count')`.
1 parent 98c81ef commit e42e290

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

lua/Comment/api.lua

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function core.__index(that, ctype)
2626

2727
---To comment lines with a count
2828
function idxd.count(count, cfg)
29-
Op.count(Config.count or count, cfg or Config:get(), that.cmode, U.ctype[ctype])
29+
Op.count(count or A.nvim_get_vvar('count'), cfg or Config:get(), that.cmode, U.ctype[ctype])
3030
end
3131

3232
---@private
@@ -237,7 +237,6 @@ function api.call(cb, op)
237237
return function()
238238
A.nvim_set_option('operatorfunc', ("v:lua.require'Comment.api'.locked'%s'"):format(cb))
239239
Config.position = Config:get().sticky and A.nvim_win_get_cursor(0) or nil
240-
Config.count = vim.v.count
241240
return op
242241
end
243242
end
@@ -259,11 +258,11 @@ function api.setup(config)
259258
K('n', cfg.opleader.block, '<Plug>(comment_toggle_blockwise)', { desc = 'Comment toggle blockwise' })
260259

261260
K('n', cfg.toggler.line, function()
262-
return vim.v.count == 0 and '<Plug>(comment_toggle_linewise_current)'
261+
return A.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)'
263262
or '<Plug>(comment_toggle_linewise_count)'
264263
end, { expr = true, desc = 'Comment toggle current line' })
265264
K('n', cfg.toggler.block, function()
266-
return vim.v.count == 0 and '<Plug>(comment_toggle_blockwise_current)'
265+
return A.nvim_get_vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)'
267266
or '<Plug>(comment_toggle_blockwise_count)'
268267
end, { expr = true, desc = 'Comment toggle current block' })
269268

lua/Comment/config.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
---@class RootConfig
9393
---@field config CommentConfig
9494
---@field position? integer[] To be used to restore cursor position
95-
---@field count integer Helps with dot-repeat support for count prefix
9695
local Config = {
9796
state = {},
9897
config = {

0 commit comments

Comments
 (0)