fix bug when inserting a terminated line after a number of unterminated parts