diff --git a/.gitignore b/.gitignore index 18098893..2deeee7f 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ luac.out *.i*86 *.x86_64 *.hex + +tmp +scratch diff --git a/README.md b/README.md index f8ebef84..2edc9337 100644 --- a/README.md +++ b/README.md @@ -156,10 +156,6 @@ These mappings are enabled by default. (config: `mappings.basic`) `gb[count]{motion}` - (Op-pending) Toggles the region using blockwise comment ``` - - -> NOTE: Dot repeat is not supported with `[count]gcc` and `[count]gbc` - - VISUAL mode ```help diff --git a/lua/Comment/api.lua b/lua/Comment/api.lua index 939106c4..0ea1ce09 100644 --- a/lua/Comment/api.lua +++ b/lua/Comment/api.lua @@ -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 #########-- @@ -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 --------------------------------------- @@ -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 @@ -230,13 +247,13 @@ function C.setup(config) map( 'n', cfg.toggler.line, - [[v:count == 0 ? 'lua require("Comment.api").call("toggle_current_linewise_op")g@$' : 'lua require("Comment.api").locked.toggle_linewise_count()']], + [[v:count == 0 ? 'lua require("Comment.api").call("toggle_current_linewise_op")g@$' : 'lua require("Comment.api").call("toggle_linewise_count_op")g@$']], expr ) map( 'n', cfg.toggler.block, - [[v:count == 0 ? 'lua require("Comment.api").call("toggle_current_blockwise_op")g@$' : 'lua require("Comment.api").locked.toggle_blockwise_count()']], + [[v:count == 0 ? 'lua require("Comment.api").call("toggle_current_blockwise_op")g@$' : 'lua require("Comment.api").call("toggle_blockwise_count_op")g@$']], expr ) map('n', cfg.opleader.line, 'lua require("Comment.api").call("toggle_linewise_op")g@', map_opt) diff --git a/lua/Comment/config.lua b/lua/Comment/config.lua index 665c2e0b..43055e34 100644 --- a/lua/Comment/config.lua +++ b/lua/Comment/config.lua @@ -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