@@ -50,23 +50,26 @@ M.normal_surround = function(args)
5050 local config = require (" nvim-surround.config" )
5151 local buffer = require (" nvim-surround.buffer" )
5252 local cache = require (" nvim-surround.cache" )
53+ local utils = require (" nvim-surround.utils" )
5354 -- Call the operatorfunc if it has not been called yet
5455 if not args .selection then
55- -- Clear the normal cache (since it was user-called)
56- cache .normal = { line_mode = args .line_mode }
56+ -- Clear the normal cache's delimiters (since it was user-called)
57+ cache .normal = { line_mode = args .line_mode , count = vim . v . count1 }
5758 M .normal_curpos = buffer .get_curpos ()
5859 M .pending_surround = true
5960
6061 vim .go .operatorfunc = " v:lua.require'nvim-surround'.normal_callback"
61- return " g@"
62+ -- TODO: Very hacky way of supporting just 1 digit, need to find better way to set v:count to 1
63+ return " <Del>g@"
6264 end
6365
6466 local first_pos = args .selection .first_pos
6567 local last_pos = { args .selection .last_pos [1 ], args .selection .last_pos [2 ] + 1 }
6668
69+ local delimiters = utils .repeat_delimiters (args .delimiters , cache .normal .count )
6770 local sticky_pos = buffer .with_extmark (M .normal_curpos , function ()
68- buffer .insert_text (last_pos , args . delimiters [2 ])
69- buffer .insert_text (first_pos , args . delimiters [1 ])
71+ buffer .insert_text (last_pos , delimiters [2 ])
72+ buffer .insert_text (first_pos , delimiters [1 ])
7073 end )
7174 buffer .restore_curpos ({
7275 first_pos = first_pos ,
@@ -75,7 +78,7 @@ M.normal_surround = function(args)
7578 })
7679
7780 if args .line_mode then
78- config .get_opts ().indent_lines (first_pos [1 ], last_pos [1 ] + # args . delimiters [1 ] + # args . delimiters [2 ] - 2 )
81+ config .get_opts ().indent_lines (first_pos [1 ], last_pos [1 ] + # delimiters [1 ] + # delimiters [2 ] - 2 )
7982 end
8083 M .pending_surround = false
8184end
0 commit comments