                 grid_focus.focus.col += 1
             else if (not grid_focus.is_across) and grid_focus.focus.row < @height() - 1
                 grid_focus.focus.row += 1
-        @setState { grid_focus: grid_focus }
+        @setState { grid_focus: @collapseGridFocus grid_focus }
 
     deleteLetter: (keyCode) ->
         grid_focus = Utils.clone @state.grid_focus


    # Stuff relating to the input fields.
    openCellField: (type) ->
        grid_focus = Utils.clone @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 = Utils.clone grid_focus
            grid_focus.field_open = "none"
        return grid_focus

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

        grid_focus = Utils.clone @state.grid_focus
        if grid_focus == null
            return


                        return "open_cell_highlighted_intermediate"
                    else
                        return "open_cell"
                else
                    if (grid_focus.focus.row == row and grid_focus.focus.col == col)
                        return "closed_cell_highlighted"
                    else
                        return "closed_cell"
            else
                # selection is more than one cell
                row1 = Math.min(grid_focus.focus.row, grid_focus.anchor.row)
                row2 = Math.max(grid_focus.focus.row, grid_focus.anchor.row)
                col1 = Math.min(grid_focus.focus.col, grid_focus.anchor.col)
                col2 = Math.max(grid_focus.focus.col, grid_focus.anchor.col)
                if (row1 <= row and row <= row2 and col1 <= col and col <= col2)
                    return (if grid[row][col].open then "open_cell_highlighted" else "closed_cell_highlighted")
                else
                    return (if grid[row][col].open then "open_cell" else "closed_cell")

        for i in [0 ... @height()]
            for j in [0 ... @width()]
                getCellClass(i, j)
