 
             if x[0] == MARKERS.cell
                 marks = cm.findMarksAt({line:line, ch:1})
-                if marks.length == 0
-                    @mark_cell_start(line)
+                if not marks? or marks.length == 0
+                    @mark_cell_start(cm, line)
                 else
                     first = true
                     for mark in marks

            cm.replaceRange('\n',{line:line+1,ch:0})
        uuid = misc.uuid()
        cm.replaceRange(MARKERS.cell + uuid + MARKERS.cell + '\n', {line:line, ch:0})
        return {marker:@mark_cell_start(line), created:true}

    remove_cell_flags_from_changeObj: (changeObj, flags) =>
        # Remove cell flags from *contiguous* text in the changeObj.

                    )()


    mark_cell_start: (cm, line) =>
        # Assuming the proper text is in the document for a new cell at this line,
        # mark it as such. This hides control codes and places a cell separation
        # element, which may be clicked to create a new cell.
        if line >= cm.lineCount()-1
            # If at bottom, insert blank lines.
            cm.replaceRange("\n\n\n", {line:line+1, ch:0})
