 
     toggleOpenness: () ->
         if @state.grid_focus != null
-            grid_focus = Utils.clone @state.grid_focus
+            grid_focus = @collapseGridFocus @state.grid_focus
             grid_focus.field_open = "none"
             @setState { grid_focus: grid_focus }
             row = grid_focus.focus.row

                            row1, col1, "contents", ""
                    grid_focus.focus.col = col1
                    grid_focus.focus.row = row1
            @setState { grid_focus: grid_focus }

    # Perform an automatic renumbering.
    renumber: () ->


    # Stuff relating to the input fields.
    openCellField: (type) ->
        grid_focus = @collapseGridFocus @state.grid_focus
        if grid_focus != null and \
                @state.puzzle.grid[grid_focus.focus.row][grid_focus.focus.col].open
            grid_focus.field_open = type
            @setState { grid_focus: grid_focus }
    removeCellField: (grid_focus) ->
        if grid_focus != null
            grid_focus = @collapseGridFocus grid_focus
            grid_focus.field_open = "none"
        return grid_focus

    # Given a grid_focus object, sets the anchor to be the focus and returns
    # the new object.
    collapseGridFocus: (grid_focus) ->
        if grid_focus != null
            grid_focus = Utils.clone grid_focus
            grid_focus.anchor =
                row: grid_focus.focus.row
                col: grid_focus.focus.col
        return grid_focus

    onCellFieldKeyPress: (event, row, col) ->
        v = event.target.value
        keyCode = event.keyCode

        grid_focus = @collapseGridFocus @state.grid_focus
        if grid_focus == null
            return

