Index: wysiwyg.init.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.init.js,v
retrieving revision 1.1
diff -u -p -r1.1 wysiwyg.init.js
--- wysiwyg.init.js	11 Oct 2008 19:54:24 -0000	1.1
+++ wysiwyg.init.js	30 Nov 2008 15:58:32 -0000
@@ -1,6 +1,6 @@
 // $Id: wysiwyg.init.js,v 1.1 2008/10/11 19:54:24 sun Exp $
 
-Drupal.wysiwyg = Drupal.wysiwyg || {};
+Drupal.wysiwyg = Drupal.wysiwyg || { 'instances': {} };
 
 Drupal.wysiwyg.editor = Drupal.wysiwyg.editor || { 'init': {}, 'attach': {}, 'detach': {} };
 
Index: wysiwyg.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/wysiwyg/wysiwyg.js,v
retrieving revision 1.2
diff -u -p -r1.2 wysiwyg.js
--- wysiwyg.js	30 Nov 2008 15:48:32 -0000	1.2
+++ wysiwyg.js	30 Nov 2008 16:01:11 -0000
@@ -84,6 +84,12 @@ Drupal.wysiwygAttach = function(context,
   if (typeof Drupal.wysiwyg.editor.attach[params.editor] == 'function') {
     // Attach editor.
     Drupal.wysiwyg.editor.attach[params.editor](context, params, (Drupal.settings.wysiwyg.configs[params.editor] ? Drupal.wysiwyg.clone(Drupal.settings.wysiwyg.configs[params.editor][params.format]) : {}));
+    // (Re-)initialize field instance.
+    Drupal.wysiwyg.instances[params.field] = {};
+    // Store editor name for this field.
+    Drupal.wysiwyg.instances[params.field].editor = params.editor;
+    // Store editor status for this field.
+    Drupal.wysiwyg.instances[params.field].status = 1;
     // Display toggle link.
     $('#wysiwyg-toggle-' + params.field).show();
   }
@@ -96,19 +102,18 @@ Drupal.wysiwygAttach = function(context,
 /**
  * Detach all editors from a target element.
  *
- * Until there is a central registry of target elements storing the currently
- * attached editor, we simply invoke the detach hook of all editors to ensure
- * that no editor is attached to the target element.
- *
  * @param context
  *   A DOM element, supplied by Drupal.attachBehaviors().
  * @param params
  *   An object containing input format parameters.
  */
 Drupal.wysiwygDetach = function(context, params) {
-  jQuery.each(Drupal.wysiwyg.editor.detach, function(editor) {
-    this(context, params);
-  });
+  var editor = Drupal.wysiwyg.instances[params.field].editor;
+  if (jQuery.isFunction(Drupal.wysiwyg.editor.detach[editor])) {
+    Drupal.wysiwyg.editor.detach[editor](context, params);
+    // @todo Unsure.
+    // Drupal.wysiwyg.instances[params.field].editor = 'none';
+  }
 }
 
 /**
@@ -122,19 +127,22 @@ Drupal.wysiwygDetach = function(context,
 Drupal.wysiwygAttachToggleLink = function(context, params) {
   var text = document.createTextNode(Drupal.settings.wysiwyg.status ? Drupal.settings.wysiwyg.disable : Drupal.settings.wysiwyg.enable);
   var a = document.createElement('a');
-  $(a).toggle(
-    function() {
+  $(a).click(function() {
+    if (Drupal.wysiwyg.instances[params.field].status) {
       Drupal.wysiwygDetach(context, params);
       $('#wysiwyg-toggle-' + params.field).html(Drupal.settings.wysiwyg.enable).blur();
       // After disabling the editor, re-attach default behaviors.
       Drupal.wysiwyg.editor.attach.none(context, params);
-    },
-    function() {
+    }
+    else {
       // Before enabling the editor, detach default behaviors.
       Drupal.wysiwyg.editor.detach.none(context, params);
+      // @todo Wrong params passed to wysiwygAttach() when editor was disabled
+      //   for format A and format is switched to format B afterwards.
       Drupal.wysiwygAttach(context, params);
       $('#wysiwyg-toggle-' + params.field).html(Drupal.settings.wysiwyg.disable).blur();
-    })
+    }
+  })
     .attr('id', 'wysiwyg-toggle-' + params.field)
     .attr('href', 'javascript:void(0);')
     .append(text);
