@@ -23,39 +23,40 @@ export def ContinueList()
2323 var variant_3 = ' \*\s\+' # * bla bla bla
2424 var variant_4 = ' \d\+\.\s\+' # 123 . bla bla bla
2525
26- var current_line = join (
27- getline (
28- search ($ ' \({variant_1}\|{variant_2}\|{variant_3}\|{variant_4}\|\n\n\)' , ' bn' ),
29- line (' .' )),
30- ' \n' )
26+ var current_line = getline (' .' )
3127
32- # Check if the current line is an item or not and check if there is only a
33- # bullet or a bullet + some text
34- # There is only a buller with no text. Next <CR> shall remove the bullet
28+ # Check if the current line is an item.
29+ # Scan the current line through the less general regex ( a regex can be
30+ # contained in another regex)
3531 var is_item = false
36- var only_bullet = false
37- # Check if you only have the bullet with no item
3832 for variant in [variant_1, variant_2, variant_3, variant_4]
39- if current_line = ~ $ ' ^\s*{variant}\s*$'
40- is_item = true
41- only_bullet = true
42- break
43- elseif current_line = ~ $ ' ^\s*{variant}\s*'
33+ if current_line = ~ $ ' ^\s*{variant}\s*'
4434 is_item = true
4535 break
46- else
47- is_item = false
4836 endif
4937 endfor
5038
51- echom is_item
39+ # If the current line is not in an item list , act as normal ,
40+ # i .e . <cr> = \n , otherwise split the current line depending on where is the
41+ # cursor
42+ var this_line = is_item
43+ ? strcharpart (getline (' .' ), 0 , col (' .' ) - 1 )
44+ : getline (' .' )
45+ var next_line = is_item
46+ ? strcharpart (getline (' .' ), col (' .' ) - 1 )
47+ : ' '
5248
53- # Scan the current line through the less general regex (a regex can be
54- # contained in another regex)
55- var this_line = is_item ? strcharpart (current_line, 0 , col (' .' ) - 1 ) : ' '
56- var next_line = is_item ? strcharpart (current_line, col (' .' ) - 1 ) : ' '
49+ # double <cr> equal to finish the itemization
50+ if this_line = ~
51+ $ ' ^\s*\({variant_1}\|{variant_2}\|{variant_3}\|{variant_4}\)\s*$'
52+ && next_line = ~ ' ^\s*$'
53+ this_line = ' '
54+ is_item = false
55+ endif
56+
57+ # Handle different cases if the current line is an item of a list
5758 var item_symbol = ' '
58- if is_item && ! only_bullet
59+ if is_item
5960 if current_line = ~ $ ' ^\s*{variant_1}'
6061 # If - [x ], the next item should be - [ ] anyway.
6162 item_symbol = $ " {current_line->matchstr($'^\s*{variant_1}')
@@ -72,15 +73,20 @@ export def ContinueList()
7273 item_symbol = $ " {current_line->matchstr($'^\s*{variant_4}')
7374 \ - >substitute (string (curr_nr), string (curr_nr + 1 ), ' ' )}"
7475 endif
75- elseif is_item && only_bullet
76- this_line = ' '
77- next_line = ' '
78- else
79- this_line = getline (' .' )
80- next_line = ' '
76+
77+ # The following is in case the cursor is on the lhs of the item_symbol
78+ if col (' .' ) < len (item_symbol)
79+ if current_line = ~ $ ' ^\s*{variant_4}'
80+ this_line = $ " {current_line->matchstr($'^\s *{variant_4}')}"
81+ next_line = strcharpart (current_line, len (item_symbol))
82+ else
83+ this_line = item_symbol
84+ next_line = strcharpart (current_line, len (item_symbol))
85+ endif
86+ endif
8187 endif
8288
83- # Add the correct newline
89+ # Add the correct lines
8490 setline (line (' .' ), this_line)
8591 append (line (' .' ), item_symbol .. next_line)
8692 cursor (line (' .' ) + 1 , len (item_symbol) + 1 )
0 commit comments