1
1
local U = require (' Comment.utils' )
2
+ local Config = require (' Comment.config' )
2
3
local A = vim .api
3
4
4
- local O = {}
5
+ local Op = {}
5
6
6
7
--- @alias VMode ' "line"' | ' "char"' | ' "v"' | ' "V"' Vim Mode. Read ` :h map-operator`
7
8
@@ -27,7 +28,7 @@ local O = {}
27
28
--- @param cmode CMode
28
29
--- @param ctype CType
29
30
--- @param cmotion CMotion
30
- function O .opfunc (vmode , cfg , cmode , ctype , cmotion )
31
+ function Op .opfunc (vmode , cfg , cmode , ctype , cmotion )
31
32
-- comment/uncomment logic
32
33
--
33
34
-- 1. type == line
@@ -75,21 +76,21 @@ function O.opfunc(vmode, cfg, cmode, ctype, cmotion)
75
76
}
76
77
77
78
if block_x then
78
- ctx .cmode = O .blockwise_x (params )
79
+ ctx .cmode = Op .blockwise_x (params )
79
80
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 )
81
82
else
82
- ctx .cmode = O .linewise (params )
83
+ ctx .cmode = Op .linewise (params )
83
84
end
84
85
85
86
-- We only need to restore cursor if both sticky and position are available
86
87
-- As this function is also called for visual mapping where we are not storing the position
87
88
--
88
89
-- And I found out that if someone presses `gc` but doesn't provide operators and
89
90
-- 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
93
94
end
94
95
95
96
U .is_fn (cfg .post_hook , ctx )
98
99
--- Linewise commenting
99
100
--- @param p OpFnParams
100
101
--- @return integer CMode
101
- function O .linewise (p )
102
+ function Op .linewise (p )
102
103
local lcs_esc , rcs_esc = U .escape (p .lcs ), U .escape (p .rcs )
103
104
local pattern = U .is_fn (p .cfg .ignore )
104
105
local padding , pp = U .get_padding (p .cfg .padding )
161
162
--- @param p OpFnParams
162
163
--- @param partial boolean Whether to do a partial or full comment
163
164
--- @return integer CMode
164
- function O .blockwise (p , partial )
165
+ function Op .blockwise (p , partial )
165
166
-- Block wise, only when there are more than 1 lines
166
167
local sln , eln = p .lines [1 ], p .lines [# p .lines ]
167
168
local lcs_esc , rcs_esc = U .escape (p .lcs ), U .escape (p .rcs )
210
211
--- Blockwise (left-right/x-axis motion) commenting
211
212
--- @param p OpFnParams
212
213
--- @return integer CMode
213
- function O .blockwise_x (p )
214
+ function Op .blockwise_x (p )
214
215
local line = p .lines [1 ]
215
216
local first = line :sub (0 , p .range .scol )
216
217
local mid = line :sub (p .range .scol + 1 , p .range .ecol + 1 )
243
244
--- @param count integer Number of lines
244
245
--- @param cfg Config
245
246
--- @param ctype CType
246
- function O .count (count , cfg , ctype )
247
+ function Op .count (count , cfg , ctype )
247
248
local lines , range = U .get_count_lines (count )
248
249
249
250
--- @type Ctx
@@ -266,12 +267,12 @@ function O.count(count, cfg, ctype)
266
267
}
267
268
268
269
if ctype == U .ctype .block then
269
- ctx .cmode = O .blockwise (params )
270
+ ctx .cmode = Op .blockwise (params )
270
271
else
271
- ctx .cmode = O .linewise (params )
272
+ ctx .cmode = Op .linewise (params )
272
273
end
273
274
274
275
U .is_fn (cfg .post_hook , ctx )
275
276
end
276
277
277
- return O
278
+ return Op
0 commit comments