Skip to content

Commit 026ec95

Browse files
authored
feat: dot-repeat support for [count]gcc and [count]gbc 🎉 (#127)
Closes #125
1 parent 00ed8f6 commit 026ec95

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,6 @@ luac.out
3838
*.i*86
3939
*.x86_64
4040
*.hex
41+
42+
tmp
43+
scratch

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,6 @@ These mappings are enabled by default. (config: `mappings.basic`)
156156
`gb[count]{motion}` - (Op-pending) Toggles the region using blockwise comment
157157
```
158158

159-
<a id="count-prefix">
160-
161-
> NOTE: Dot repeat is not supported with `[count]gcc` and `[count]gbc`
162-
163159
- VISUAL mode
164160

165161
```help

lua/Comment/api.lua

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,15 @@ end
3535
---Toggle linewise-comment over multiple lines using `vim.v.count`
3636
---@param cfg? Config
3737
function C.toggle_linewise_count(cfg)
38-
Op.count(vim.v.count, cfg or Config:get(), U.ctype.line)
38+
local c = Config:get()
39+
Op.count(c.__count or vim.v.count, cfg or c, U.ctype.line)
40+
end
41+
42+
---@private
43+
---(Operator-Pending) Toggle linewise-comment over using `vim.v.count`
44+
---@param cfg? Config
45+
function C.toggle_linewise_count_op(_, cfg)
46+
C.toggle_linewise_count(cfg)
3947
end
4048

4149
--######### BLOCKWISE #########--
@@ -63,7 +71,15 @@ end
6371
---Toggle blockwise-comment over multiple lines using `vim.v.count`
6472
---@param cfg? Config
6573
function C.toggle_blockwise_count(cfg)
66-
Op.count(vim.v.count, cfg or Config:get(), U.ctype.block)
74+
local c = Config:get()
75+
Op.count(c.__count or vim.v.count, cfg or c, U.ctype.block)
76+
end
77+
78+
---@private
79+
---(Operator-Pending) Toggle blockwise-comment over `vim.v.count`
80+
---@param cfg? Config
81+
function C.toggle_blockwise_count_op(_, cfg)
82+
C.toggle_blockwise_count(cfg)
6783
end
6884

6985
---------------------------------------
@@ -211,6 +227,7 @@ function C.call(cb)
211227
local cfg = Config:get()
212228
A.nvim_set_option('operatorfunc', ("v:lua.require'Comment.api'.locked.%s"):format(cb))
213229
cfg.__pos = cfg.sticky and A.nvim_win_get_cursor(0)
230+
cfg.__count = vim.v.count
214231
end
215232

216233
---Configures the whole plugin
@@ -230,13 +247,13 @@ function C.setup(config)
230247
map(
231248
'n',
232249
cfg.toggler.line,
233-
[[v:count == 0 ? '<CMD>lua require("Comment.api").call("toggle_current_linewise_op")<CR>g@$' : '<CMD>lua require("Comment.api").locked.toggle_linewise_count()<CR>']],
250+
[[v:count == 0 ? '<CMD>lua require("Comment.api").call("toggle_current_linewise_op")<CR>g@$' : '<CMD>lua require("Comment.api").call("toggle_linewise_count_op")<CR>g@$']],
234251
expr
235252
)
236253
map(
237254
'n',
238255
cfg.toggler.block,
239-
[[v:count == 0 ? '<CMD>lua require("Comment.api").call("toggle_current_blockwise_op")<CR>g@$' : '<CMD>lua require("Comment.api").locked.toggle_blockwise_count()<CR>']],
256+
[[v:count == 0 ? '<CMD>lua require("Comment.api").call("toggle_current_blockwise_op")<CR>g@$' : '<CMD>lua require("Comment.api").call("toggle_blockwise_count_op")<CR>g@$']],
240257
expr
241258
)
242259
map('n', cfg.opleader.line, '<CMD>lua require("Comment.api").call("toggle_linewise_op")<CR>g@', map_opt)

lua/Comment/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
---@field pre_hook fun(ctx: Ctx):string Function to be called before comment/uncomment
4545
---@field post_hook fun(ctx:Ctx) Function to be called after comment/uncomment
4646
---@field __pos number[] To be used to restore cursor position
47+
---@field __count number Helps with dot-repeat support for count prefix
4748

4849
---@class RootConfig
4950
---@field config Config

0 commit comments

Comments
 (0)