Fix problem with new segment insertion.
Fix problem with new segment insertion.

With @Jenbongo's help.

JonyEpsilon/gorilla-repl,JonyEpsilon/gorilla-repl,deas/gorilla-notebook,deas/gorilla-notebook,deas/gorilla-notebook,rcdexta/gorilla_repl_cia,deas/gorilla-notebook,gorillalabs/gorilla-repl,mrcslws/gorilla-repl,mrcslws/gorilla-repl,gorillalabs/gorilla-repl