Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ luac.out
*.i*86
*.x86_64
*.hex

tmp
scratch
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ These mappings are enabled by default. (config: `mappings.basic`)
`gb[count]{motion}` - (Op-pending) Toggles the region using blockwise comment
```

<a id="count-prefix">

> NOTE: Dot repeat is not supported with `[count]gcc` and `[count]gbc`

- VISUAL mode

```help
Expand Down
25 changes: 21 additions & 4 deletions lua/Comment/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ end
---Toggle linewise-comment over multiple lines using `vim.v.count`
---@param cfg? Config
function C.toggle_linewise_count(cfg)
Op.count(vim.v.count, cfg or Config:get(), U.ctype.line)
local c = Config:get()
Op.count(c.__count or vim.v.count, cfg or c, U.ctype.line)
end

---@private
---(Operator-Pending) Toggle linewise-comment over using `vim.v.count`
---@param cfg? Config
function C.toggle_linewise_count_op(_, cfg)
C.toggle_linewise_count(cfg)
end

--######### BLOCKWISE #########--
Expand Down Expand Up @@ -63,7 +71,15 @@ end
---Toggle blockwise-comment over multiple lines using `vim.v.count`
---@param cfg? Config
function C.toggle_blockwise_count(cfg)
Op.count(vim.v.count, cfg or Config:get(), U.ctype.block)
local c = Config:get()
Op.count(c.__count or vim.v.count, cfg or c, U.ctype.block)
end

---@private
---(Operator-Pending) Toggle blockwise-comment over `vim.v.count`
---@param cfg? Config
function C.toggle_blockwise_count_op(_, cfg)
C.toggle_blockwise_count(cfg)
end

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

---Configures the whole plugin
Expand All @@ -230,13 +247,13 @@ function C.setup(config)
map(
'n',
cfg.toggler.line,
[[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>']],
[[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@$']],
expr
)
map(
'n',
cfg.toggler.block,
[[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>']],
[[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@$']],
expr
)
map('n', cfg.opleader.line, '<CMD>lua require("Comment.api").call("toggle_linewise_op")<CR>g@', map_opt)
Expand Down
1 change: 1 addition & 0 deletions lua/Comment/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
---@field pre_hook fun(ctx: Ctx):string Function to be called before comment/uncomment
---@field post_hook fun(ctx:Ctx) Function to be called after comment/uncomment
---@field __pos number[] To be used to restore cursor position
---@field __count number Helps with dot-repeat support for count prefix

---@class RootConfig
---@field config Config
Expand Down