 
     Carmenta.bind 'unfocus:regions', (event) =>
       @element.removeClass('focus')
+      Carmenta.trigger('region:blurred', {region: @})
+
+    Carmenta.bind 'focus:window', (event) =>
+      @element.removeClass('focus')
+      Carmenta.trigger('region:blurred', {region: @})
+
+    Carmenta.bind 'focus:frame', =>
+      return if @previewing
+      return unless Carmenta.region == @
+      @focus()
 
     Carmenta.bind 'action', (event, options) =>
       return if @previewing
       return unless Carmenta.region == @
       @execCommand(options.action, options) if options.action
 
+    $(@document).keydown (event) =>
+      return if @previewing
+      return unless Carmenta.region == @
+      Carmenta.changes = true
+      switch event.keyCode
+
+        when 90 # undo / redo
+          return unless event.metaKey
+          event.preventDefault()
+          if event.shiftKey
+            @execCommand('redo')
+          else
+            @execCommand('undo')
+
+          return
+
+
     @element.mouseup =>
+      return if @previewing
       Carmenta.trigger('region:focused', {region: @})
       @focus()
 
     @element.mousemove (event) =>
-      snippet = $(event.target).closest('.carmenta-snippet')
-      @toolbar.show(snippet) if snippet.length
+      return if @previewing
+      return unless Carmenta.region == @
+      @snippet = $(event.target).closest('.carmenta-snippet')
+      if @snippet.length
+        @snippet.mouseout => @toolbar.hide()
+        @toolbar.show(@snippet)
 
     @element.mouseout (event) =>
+      @toolbar.hide()
 
 
   togglePreview: ->



  pushHistory: ->
    @history.push('frist!!!!') # !remove
    @history.push(@html())


  execCommand: (action, options) ->
    @focus()
    @pushHistory() unless action == 'undo' || action == 'redo'

    Carmenta.log('execCommand', action, options.value)

    handler.call(@, options) if handler = Carmenta.Regions.Snippetable.actions[action]




  undo: -> @html(@history.undo())

  redo: -> @html(@history.redo())

  removesnippet: ->
    @snippet.remove() if @snippet
    @toolbar.hide(true)