11local U = require (' Comment.utils' )
2+ local Config = require (' Comment.config' )
23local A = vim .api
34
4- local O = {}
5+ local Op = {}
56
67--- @alias VMode ' "line"' | ' "char"' | ' "v"' | ' "V"' Vim Mode. Read ` :h map-operator`
78
@@ -27,7 +28,7 @@ local O = {}
2728--- @param cmode CMode
2829--- @param ctype CType
2930--- @param cmotion CMotion
30- function O .opfunc (vmode , cfg , cmode , ctype , cmotion )
31+ function Op .opfunc (vmode , cfg , cmode , ctype , cmotion )
3132 -- comment/uncomment logic
3233 --
3334 -- 1. type == line
@@ -75,21 +76,21 @@ function O.opfunc(vmode, cfg, cmode, ctype, cmotion)
7576 }
7677
7778 if block_x then
78- ctx .cmode = O .blockwise_x (params )
79+ ctx .cmode = Op .blockwise_x (params )
7980 elseif ctype == U .ctype .block and not same_line then
80- ctx .cmode = O .blockwise (params , partial_block )
81+ ctx .cmode = Op .blockwise (params , partial_block )
8182 else
82- ctx .cmode = O .linewise (params )
83+ ctx .cmode = Op .linewise (params )
8384 end
8485
8586 -- We only need to restore cursor if both sticky and position are available
8687 -- As this function is also called for visual mapping where we are not storing the position
8788 --
8889 -- And I found out that if someone presses `gc` but doesn't provide operators and
8990 -- does visual comments then cursor jumps to previous stored position. Thus the check for visual modes
90- if cfg .sticky and cfg . __pos and cmotion ~= U .cmotion .v and cmotion ~= U .cmotion .V then
91- A .nvim_win_set_cursor (0 , cfg . __pos )
92- cfg . __pos = nil
91+ if cfg .sticky and Config . position and cmotion ~= U .cmotion .v and cmotion ~= U .cmotion .V then
92+ A .nvim_win_set_cursor (0 , Config . position )
93+ Config . position = nil
9394 end
9495
9596 U .is_fn (cfg .post_hook , ctx )
9899--- Linewise commenting
99100--- @param p OpFnParams
100101--- @return integer CMode
101- function O .linewise (p )
102+ function Op .linewise (p )
102103 local lcs_esc , rcs_esc = U .escape (p .lcs ), U .escape (p .rcs )
103104 local pattern = U .is_fn (p .cfg .ignore )
104105 local padding , pp = U .get_padding (p .cfg .padding )
161162--- @param p OpFnParams
162163--- @param partial boolean Whether to do a partial or full comment
163164--- @return integer CMode
164- function O .blockwise (p , partial )
165+ function Op .blockwise (p , partial )
165166 -- Block wise, only when there are more than 1 lines
166167 local sln , eln = p .lines [1 ], p .lines [# p .lines ]
167168 local lcs_esc , rcs_esc = U .escape (p .lcs ), U .escape (p .rcs )
210211--- Blockwise (left-right/x-axis motion) commenting
211212--- @param p OpFnParams
212213--- @return integer CMode
213- function O .blockwise_x (p )
214+ function Op .blockwise_x (p )
214215 local line = p .lines [1 ]
215216 local first = line :sub (0 , p .range .scol )
216217 local mid = line :sub (p .range .scol + 1 , p .range .ecol + 1 )
243244--- @param count integer Number of lines
244245--- @param cfg Config
245246--- @param ctype CType
246- function O .count (count , cfg , ctype )
247+ function Op .count (count , cfg , ctype )
247248 local lines , range = U .get_count_lines (count )
248249
249250 --- @type Ctx
@@ -266,12 +267,12 @@ function O.count(count, cfg, ctype)
266267 }
267268
268269 if ctype == U .ctype .block then
269- ctx .cmode = O .blockwise (params )
270+ ctx .cmode = Op .blockwise (params )
270271 else
271- ctx .cmode = O .linewise (params )
272+ ctx .cmode = Op .linewise (params )
272273 end
273274
274275 U .is_fn (cfg .post_hook , ctx )
275276end
276277
277- return O
278+ return Op
0 commit comments