Index: /FCKeditor/trunk/editor/_source/internals/fck.js
===================================================================
--- /FCKeditor/trunk/editor/_source/internals/fck.js	(revision 184)
+++ /FCKeditor/trunk/editor/_source/internals/fck.js	(revision 185)
@@ -48,10 +48,15 @@
 	IsDirty : function()
 	{
-		return ( this.StartupValue != this.EditorDocument.body.innerHTML ) ;
+		if ( this.EditMode == FCK_EDITMODE_SOURCE )
+			return ( this.StartupValue != this.EditingArea.Textarea.value ) ;
+		else
+			return ( this.StartupValue != this.EditorDocument.body.innerHTML ) ;
 	},
 
 	ResetIsDirty : function()
 	{
-		if ( this.EditorDocument.body )
+		if ( this.EditMode == FCK_EDITMODE_SOURCE )
+			this.StartupValue = this.EditingArea.Textarea.value ;
+		else if ( this.EditorDocument.body )
 			this.StartupValue = this.EditorDocument.body.innerHTML ;
 	},
@@ -86,5 +91,5 @@
 
 		// Set the editor's startup contents
-		this.SetHTML( this.GetLinkedFieldValue() ) ;
+		this.SetHTML( this.GetLinkedFieldValue(), true ) ;
 	},
 
@@ -300,5 +305,5 @@
 	},
 
-	SetHTML : function( html )
+	SetHTML : function( html, resetIsDirty )
 	{
 		this.EditingArea.Mode = FCK.EditMode ;
@@ -320,4 +325,6 @@
 				html = html.replace( FCKRegexLib.EmCloser, '<\/i>' ) ;
 			}
+			
+			this._ForceResetIsDirty = ( resetIsDirty === true ) ;
 
 			var sHtml = '' ;
@@ -416,4 +423,7 @@
 			// Removes the enter key handler.
 			FCK.EnterKeyHandler = null ;
+			
+			if ( resetIsDirty )
+				this.ResetIsDirty() ;
 
 			// Listen for keystroke events.
@@ -530,4 +540,8 @@
 	{
 		var bIsWysiwyg = ( FCK.EditMode == FCK_EDITMODE_WYSIWYG ) ;
+
+		// Save the current IsDirty state, so we may restore it after the switch.
+		var bIsDirty = FCK.IsDirty() ;
+
 		var sHtml ;
 
@@ -548,6 +562,6 @@
 		FCK.EditMode = bIsWysiwyg ? FCK_EDITMODE_SOURCE : FCK_EDITMODE_WYSIWYG ;
 
-		FCK.SetHTML( sHtml ) ;
-
+		FCK.SetHTML( sHtml, !bIsDirty ) ;
+		
 		// Set the Focus.
 		FCK.Focus() ;
@@ -623,4 +637,7 @@
 	// Listen for keystroke events.
 	FCK.KeystrokeHandler.AttachToElement( FCK.EditorDocument ) ;
+	
+	if ( FCK._ForceResetIsDirty )
+		FCK.ResetIsDirty() ;
 
 	FCK.OnAfterSetHTML() ;
@@ -629,7 +646,4 @@
 	if ( FCK.Status != FCK_STATUS_NOTLOADED )
 		return ;
-
-	// Save the startup value for the "IsDirty()" check.
-	FCK.ResetIsDirty() ;
 
 	FCK.SetStatus( FCK_STATUS_ACTIVE ) ;
