                     input_line = context.input_line
                     if not input_line?
                         input_line = line - 1
-                        while input_line >= 1 and cm.getLine(input_line)[0] != MARKERS.cell
+                        while input_line >= 0 and cm.getLine(input_line)[0] != MARKERS.cell
                             input_line -= 1
                     @_process_line_gutter(cm, line, 'number', line - input_line) # relative line number
                 else

                @_process_sage_updates(opts.cm, opts.start, opts.stop)
        catch e
            console.log("Error rendering worksheet", e)
        ##console.log("process_sage_updates(opts=#{misc.to_json({caller:opts.caller, start:opts.start, stop:opts.stop})}): time=#{misc.mswalltime(tm)}ms")
        after = @editor.codemirror.getValue()
        if before != after and not @readonly
            @_syncstring.set(after)

            @_handle_input_cell_click0(e, mark)
        return false

    # Process the codemirror gutter local SMC line number and input/output toggles
    #   cm = codemirror editor
    #   line = the line number (0 based)
    #   mode = the mode for the line: 'show', 'hide', 'number'
    #   relative_line = the relative line number
    _process_line_gutter: (cm, line, mode, relative_line) =>
        # nb: I did implement a non-jQuery version of this function; the speed was *identical*.
        want = mode + relative_line  # we want the HTML node to have these params.
        elt  = cm.lineInfo(line).gutterMarkers?['smc-sagews-gutter-hide-show']
        if elt?.smc_cur == want  # gutter is already defined and set as desired.
            return
        switch mode
            when 'show'
                # A show toggle triangle
                elt = open_gutter_elt.clone()[0]
            when 'hide'
                # A hide triangle
                elt = folded_gutter_elt.clone()[0]
            when 'number'
                # A line number
                if not @editor.opts.line_numbers
                    # Ignore because line numbers are disabled
                    return
                if elt?.className == ''
                    # Gutter elt is already a plain div, so just chnage innerHTML
                    elt.smc_cur = want
                    elt.innerHTML = relative_line
                    return
                # New gutter element
                elt = line_number_elt.clone().text(relative_line)[0]
        elt.smc_cur = want  # elt will have this mode/line
        # Now set it.
        cm.setGutterMarker(line, 'smc-sagews-gutter-hide-show', elt)

    _process_line: (cm, line, context) =>
