 
       Smalruby.Views.CharacterModalView.setCharacter(c).render()
 
-    @new_block_position = _.clone(Smalruby.CharacterSelectorView.NEW_BLOCK_POSITION)
-    @prev_block = null
-
     @render()
 
   render: ->

  el: '#character-selector-tab'

  initialize: ->
    @listenTo(@model, name, @render) for name in ['add', 'remove', 'reset', 'change']

    @templateText = $('#character-selector-template').text()

        '-moz-transform': rotate
        '-webkit-transform': rotate
        transform: rotate

  addBlock_: (character) ->
    newBlock = new Blockly.Block(Blockly.mainWorkspace, 'character_new')
    newBlock.setCharacter(character)
    newBlock.initSvg()
    newBlock.render()
    @moveByNewBlock_(newBlock)
    newBlock.select()

  moveByNewBlock_: (newBlock) ->
    metrics = Blockly.mainWorkspace.getMetrics()
    newXY =
      x: metrics.viewLeft + @klass.NEW_BLOCK_MARGIN.LEFT
      y: metrics.viewTop + @klass.NEW_BLOCK_MARGIN.TOP

    if @prevBlock
      xy = @prevBlock.getRelativeToSurfaceXY()
      hw = @prevBlock.getHeightWidth()
      newHW = newBlock.getHeightWidth()
      if xy.x == @prevXY.x && xy.y == @prevXY.y
        x = xy.x
        y = xy.y + hw.height + @klass.NEW_BLOCK_MARGIN.TOP
        if y + newHW.height > metrics.viewTop + metrics.viewHeight
          x += hw.width + @klass.NEW_BLOCK_MARGIN.LEFT
          y = newXY.y
      else
        x = @prevXY.x
        y = @prevXY.y
      if x >= metrics.viewLeft &&
         x + newHW.width <= metrics.viewLeft + metrics.viewWidth &&
         y >= metrics.viewTop &&
         y + newHW.height <= metrics.viewTop + metrics.viewHeight
        newXY.x = x
        newXY.y = y

    newBlock.moveBy(newXY.x, newXY.y)

    @prevBlock = newBlock
    @prevXY = newBlock.getRelativeToSurfaceXY()

  removeCharacter_: (character) ->
    unless character.get('using')
      Smalruby.Collections.CharacterSet.remove(character)

}, {
  NEW_BLOCK_MARGIN:
    LEFT: 20
    TOP: 20
})
