@@ -566,11 +566,21 @@ fun! s:insert_new_bullet()
566566 " searching up from there
567567 let l: send_return = 1
568568 let l: normal_mode = mode () == # ' n'
569+ let l: insert_mode = mode () == # ' i'
569570 let l: indent_next = s: line_ends_in_colon (l: curr_line_num ) && g: bullets_auto_indent_after_colon
571+ let l: text_after_cursor = ' '
572+
573+ " check if current line is a bullet
574+ if l: bullet != {}
575+ " check whether we're in the middle of the line (for insert mode only)
576+ if ! s: is_at_eol () && ! s: is_at_first_col () && l: insert_mode
577+ let l: col = col (' .' )
578+ let l: curr_line = getline (' .' )
579+ let l: text_before_cursor = l: curr_line [:l: col- 2 ]
580+ let l: text_after_cursor = l: curr_line [l: col- 1 :]
581+ call setline (l: curr_line_num , l: text_before_cursor )
582+ endif
570583
571- " check if current line is a bullet and we are at the end of the line (for
572- " insert mode only)
573- if l: bullet != {} && (l: normal_mode || s: is_at_eol ())
574584 " was any text entered after the bullet?
575585 if l: bullet .text_after_bullet == # ' '
576586 " We don't want to create a new bullet if the previous one was not used,
@@ -588,6 +598,10 @@ fun! s:insert_new_bullet()
588598 let l: next_bullet_list = [s: pad_to_length (l: next_bullet , l: bullet .bullet_length)]
589599 endif
590600
601+ if l: text_after_cursor !=# ' '
602+ let l: next_bullet_list [0 ] = l: next_bullet_list [0 ] . l: text_after_cursor
603+ endif
604+
591605 " prepend blank lines if desired
592606 if g: bullets_line_spacing > 1
593607 let l: next_bullet_list += map (range (g: bullets_line_spacing - 1 ), ' ""' )
@@ -600,7 +614,11 @@ fun! s:insert_new_bullet()
600614
601615 " go to next line after the new bullet
602616 let l: col = strlen (getline (l: next_line_num )) + 1
603- call setpos (' .' , [0 , l: next_line_num , l: col ])
617+ if l: text_after_cursor == # ' '
618+ call setpos (' .' , [0 , l: next_line_num , l: col ])
619+ else
620+ call setpos (' .' , [0 , l: next_line_num , l: bullet .bullet_length + 1 ])
621+ endif
604622
605623 " indent if previous line ended in a colon
606624 if l: indent_next
@@ -635,6 +653,10 @@ fun! s:is_at_eol()
635653 return strlen (getline (' .' )) + 1 == # col (' .' )
636654endfun
637655
656+ fun ! s: is_at_first_col ()
657+ return col (' .' ) == # 1
658+ endfun
659+
638660command ! InsertNewBullet call <SID> insert_new_bullet ()
639661
640662" Helper for Colon Indent
0 commit comments