<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/root_responder_hacks.js</filename>
    </added>
    <added>
      <filename>mixins/inline_text_field.js</filename>
    </added>
    <added>
      <filename>views/text_field.js</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -36,12 +36,16 @@ RichText.EditorView = SC.FieldView.extend(
     return this.$('iframe');
   },
 
-  $inputDoc: function(){
-    return this.$input().map(function(){ return this.contentWindow.document; });
+  $inputWindow: function(){
+    return this.$input().map(function(){ return this.contentWindow; });
+  },
+
+  $inputDocument: function(){
+    return this.$inputWindow().map(function(){ return this.document; });
   },
 
   $inputBody: function(){
-    return this.$inputDoc().map(function(){ return this.body; });
+    return this.$inputDocument().map(function(){ return this.body; });
   },
 
 // Accessors
@@ -205,17 +209,17 @@ RichText.EditorView = SC.FieldView.extend(
   },
 
   _setupEditor: function(){
-    var inputDoc = this.$inputDoc(),
-        inputDocInstance = inputDoc.get(0),
+    var inputDocument = this.$inputDocument(),
+        inputDocumentInstance = inputDocument.get(0),
         stylesheets = this.get('stylesheets'),
         headers = '', idx;
 
     try {
-      inputDocInstance.designMode = 'on';
+      inputDocumentInstance.designMode = 'on';
     } catch ( e ) {
       // Will fail on Gecko if the editor is placed in an hidden container element
       // The design mode will be set ones the editor is focused
-      inputDoc.focus(function() { inputDocInstance.designMode(); } );
+      inputDocument.focus(function() { inputDocumentInstance.designMode(); } );
     }
 
     for(idx=0; idx &lt; stylesheets.length; idx++) {
@@ -223,20 +227,39 @@ RichText.EditorView = SC.FieldView.extend(
     }
 
     // TODO: Is this the best way to do it?
-    // inputDocInstance.open();
-    inputDocInstance.write(&quot;&lt;html&gt;&lt;head&gt;%@&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;&quot;.fmt(headers));
-    // inputDocInstance.close();
+    // inputDocumentInstance.open();
+    inputDocumentInstance.write(&quot;&lt;html&gt;&lt;head&gt;%@&lt;/head&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;&quot;.fmt(headers));
+    // inputDocumentInstance.close();
 
     this.set('editorIsReady', YES);
 
     this.setFieldValue(this.get('fieldValue'));
 
-    SC.Event.add(this.$inputDoc(), 'keyup', this, this._field_fieldValueDidChange);
+    SC.Event.add(this.$inputDocument(), 'keyup', this, this._field_fieldValueDidChange);
+    SC.Event.add(this.$inputDocument(), 'focus', this, this._field_fieldDidFocus);
+    SC.Event.add(this.$inputDocument(), 'blur', this, this._field_fieldDidBlur);
   },
 
   willDestroyLayer: function() {
-    SC.Event.remove(this.$inputDoc(), 'keyup', this, this._field_fieldValueDidChange);
-    SC.Event.remove(this.$input(), 'load', this, this._setupEditor);
+    SC.Event.remove(this.$inputDocument(), 'blur', this, this._field_fieldDidBlur);
+    SC.Event.remove(this.$inputDocument(), 'focus', this, this._field_fieldDidFocus);
+    SC.Event.remove(this.$inputDocument(), 'keyup', this, this._field_fieldValueDidChange);
+    SC.Event.remove(this.$input(), 'load', this, this._check_iFrameDidLoad);
+  },
+
+  _loseBlur: function(){
+    if (this._isFocused) {
+      this._isFocused = NO;
+      SC.RootResponder.responder.set('richTextEditorHasFocus', NO);
+    }
+  },
+
+  _field_fieldDidFocus: function(){
+    this.becomeFirstResponder();
+  },
+
+  _field_fieldDidBlur: function(){
+    this._loseBlur();
   },
 
   willBecomeKeyResponderFrom: function(keyView) {
@@ -245,11 +268,16 @@ RichText.EditorView = SC.FieldView.extend(
       this._isFocused = YES ;
       this.becomeFirstResponder();
       if (this.get('isVisibleInWindow')) {
-        this.$input().get(0).focus();
+        SC.RootResponder.responder.set('richTextEditorHasFocus', YES);
+        this.$inputWindow().get(0).focus();
       }
     }
   },
 
+  willLoseKeyResponderTo: function(responder) {
+    this._loseBlur();
+  },
+
 // Editor actions
 
   boldSelection: function() {
@@ -257,8 +285,8 @@ RichText.EditorView = SC.FieldView.extend(
   },
 
   iframeExecCommand: function() {
-    var inputDocInstance = this.$inputDoc().get(0);
-    return inputDocInstance.execCommand.apply(inputDocInstance, arguments);
+    var inputDocumentInstance = this.$inputDocument().get(0);
+    return inputDocumentInstance.execCommand.apply(inputDocumentInstance, arguments);
   }
 
 });</diff>
      <filename>views/editor.js</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>66ea21a6d3f8e831618eb711b279ed2721defae0</id>
    </parent>
  </parents>
  <author>
    <name>Peter Wagenet</name>
    <email>peter.wagenet@gmail.com</email>
  </author>
  <url>http://github.com/rxcfc/rich_text/commit/a94cf819c8c767f30c78ddb3c2ddc3bf2265f15a</url>
  <id>a94cf819c8c767f30c78ddb3c2ddc3bf2265f15a</id>
  <committed-date>2009-11-03T09:50:00-08:00</committed-date>
  <authored-date>2009-11-03T09:50:00-08:00</authored-date>
  <message>Better behavior for focus/blur and responders</message>
  <tree>adf0f642e36dc41537674577c01ebf9162b2d582</tree>
  <committer>
    <name>Peter Wagenet</name>
    <email>peter.wagenet@gmail.com</email>
  </committer>
</commit>
