Index: /FCKeditor/trunk/editor/_source/classes/fckenterkey.js
===================================================================
--- /FCKeditor/trunk/editor/_source/classes/fckenterkey.js	(revision 473)
+++ /FCKeditor/trunk/editor/_source/classes/fckenterkey.js	(revision 474)
@@ -44,4 +44,5 @@
 		[ 13		, 'Enter' ],
 		[ SHIFT + 13, 'ShiftEnter' ],
+		[ 9 		, 'Tab' ],
 		[ 8			, 'Backspace' ],
 		[ 46		, 'Delete' ]
@@ -53,5 +54,4 @@
 		while ( tabSpaces-- > 0 )
 			this.TabText += '\xa0' ;
-		oKeystrokeHandler.SetKeystrokes( [ 9, 'Tab' ] ) ;
 	}
 
@@ -86,5 +86,5 @@
 				return oEnterKey.DoDelete() ;
 				break ;
-			case "Tab" :
+			case 'Tab' :
 				return oEnterKey.DoTab() ;
 		}
@@ -337,8 +337,11 @@
 	}
 
-	oRange.DeleteContents() ;
-	oRange.InsertNode( this.Window.document.createTextNode( this.TabText ) ) ;
-	oRange.Collapse( false ) ;
-	oRange.Select() ;
+	if ( this.TabText )
+	{
+		oRange.DeleteContents() ;
+		oRange.InsertNode( this.Window.document.createTextNode( this.TabText ) ) ;
+		oRange.Collapse( false ) ;
+		oRange.Select() ;
+	}
 	return true ;
 }
Index: /FCKeditor/trunk/editor/_source/internals/fck.js
===================================================================
--- /FCKeditor/trunk/editor/_source/internals/fck.js	(revision 473)
+++ /FCKeditor/trunk/editor/_source/internals/fck.js	(revision 474)
@@ -81,7 +81,4 @@
 		oKeystrokeHandler.SetKeystrokes( FCKConfig.Keystrokes ) ;
 
-		// Set the <Tab> key handling.
-		oKeystrokeHandler.SetKeystrokes( [ 9, 'Tab' ] ) ;
-
 		// In IE7, if the editor tries to access the clipboard by code, a dialog is
 		// shown to the user asking if the application is allowed to access or not.
@@ -103,6 +100,9 @@
 		FCKListsLib.Setup() ;
 
-		// Set the editor's startup contents
+		// Set the editor's startup contents.
 		this.SetData( this.GetLinkedFieldValue(), true ) ;
+
+		// Tab key handling for source mode.
+		FCKTools.AddEventListener( document, "keydown", this._TabKeyHandler ) ;
 	},
 
@@ -677,115 +677,15 @@
 			FCKUndo.SaveUndoStep() ;
 		}
-	}
-} ;
-
-FCK.Events	= new FCKEvents( FCK ) ;
-
-// DEPRECATED in favor or "GetData".
-FCK.GetHTML	= FCK.GetXHTML = FCK.GetData ;
-
-// DEPRECATED in favor of "SetData".
-FCK.SetHTML = FCK.SetData ;
-
-// InsertElementAndGetIt and CreateElement are Deprecated : returns the same value as InsertElement.
-FCK.InsertElementAndGetIt = FCK.CreateElement = FCK.InsertElement ;
-
-// Replace all events attributes (like onclick).
-function _FCK_ProtectEvents_ReplaceTags( tagMatch )
-{
-	return tagMatch.replace( FCKRegexLib.EventAttributes, _FCK_ProtectEvents_ReplaceEvents ) ;
-}
-
-// Replace an event attribute with its respective __fckprotectedatt attribute.
-// The original event markup will be encoded and saved as the value of the new
-// attribute.
-function _FCK_ProtectEvents_ReplaceEvents( eventMatch, attName )
-{
-	return ' ' + attName + '_fckprotectedatt="' + FCKTools.EncodeToHex( eventMatch ) + '"' ;
-}
-
-function _FCK_ProtectEvents_RestoreEvents( match, encodedOriginal )
-{
-	return FCKTools.DecodeHex( encodedOriginal ) ;
-}
-
-function _FCK_EditingArea_OnLoad()
-{
-	// Get the editor's window and document (DOM)
-	FCK.EditorWindow	= FCK.EditingArea.Window ;
-	FCK.EditorDocument	= FCK.EditingArea.Document ;
-
-	FCK.InitializeBehaviors() ;
-
-	// Create the enter key handler
-	if ( !FCKConfig.DisableEnterKeyHandler )
-		FCK.EnterKeyHandler = new FCKEnterKey( FCK.EditorWindow, FCKConfig.EnterMode, FCKConfig.ShiftEnterMode, FCKConfig.TabSpaces ) ;
-
-	// Listen for keystroke events.
-	FCK.KeystrokeHandler.AttachToElement( FCK.EditorDocument ) ;
-
-	if ( FCK._ForceResetIsDirty )
-		FCK.ResetIsDirty() ;
-
-	// This is a tricky thing for IE. In some cases, even if the cursor is
-	// blinking in the editing, the keystroke handler doesn't catch keyboard
-	// events. We must activate the editing area to make it work. (#142).
-	if ( FCKBrowserInfo.IsIE && FCK.HasFocus )
-		FCK.EditorDocument.body.setActive() ;
-
-	FCK.OnAfterSetHTML() ;
-
-	// Check if it is not a startup call, otherwise complete the startup.
-	if ( FCK.Status != FCK_STATUS_NOTLOADED )
-		return ;
-
-	FCK.SetStatus( FCK_STATUS_ACTIVE ) ;
-}
-
-function _FCK_GetEditorAreaStyleTags()
-{
-	var sTags = '' ;
-	var aCSSs = FCKConfig.EditorAreaCSS ;
-	var sStyles = FCKConfig.EditorAreaStyles ;
-
-	for ( var i = 0 ; i < aCSSs.length ; i++ )
-		sTags += '<link href="' + aCSSs[i] + '" rel="stylesheet" type="text/css" />' ;
-
-	if ( sStyles && sStyles.length > 0 )
-		sTags += "<style>" + sStyles + "</style>" ;
-
-	return sTags ;
-}
-
-function _FCK_KeystrokeHandler_OnKeystroke( keystroke, keystrokeValue )
-{
-	if ( FCK.Status != FCK_STATUS_COMPLETE )
-		return false ;
-
-	if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
-	{
-		switch ( keystrokeValue )
-		{
-			case 'Paste' :
-				return !FCK.Events.FireEvent( 'OnPaste' ) ;
-
-			case 'Cut' :
-				FCKUndo.SaveUndoStep() ;
-				return false ;
-
-			case 'Tab' :
-				// Ignore it here, it's handled in fckenterkey.js.
-				return false ;
-		}
-	}
-	else
-	{
-		// In source mode, some actions must have their default behavior.
-		if ( keystrokeValue.Equals( 'Paste', 'Undo', 'Redo', 'SelectAll' ) )
-			return false ;
+	},
+
+	_TabKeyHandler : function( evt )
+	{
+		if ( ! evt )
+			evt = window.event ;
+		var keystrokeValue = evt.keyCode ;
 
 		// Pressing <Tab> in source mode should produce a tab space in the text area, not
 		// changing the focus to something else.
-		if ( keystrokeValue == 'Tab' )
+		if ( keystrokeValue == 9 && FCK.EditMode != FCK_EDITMODE_WYSIWYG )
 		{
 			if ( FCKBrowserInfo.IsIE )
@@ -793,5 +693,5 @@
 				var range = document.selection.createRange() ;
 				if ( range.parentElement() != FCK.EditingArea.Textarea ) 
-					return false ;
+					return ;
 				range.text = '\t' ;
 				range.select() ;
@@ -809,6 +709,112 @@
 				el.setSelectionRange( selStart + 1, selStart + 1 ) ;
 			}
-			return true ;
-		}
+			if ( evt.preventDefault )
+				return evt.preventDefault() ;
+			else
+				return ( evt.returnValue = false ) ;
+		}
+	}
+} ;
+
+FCK.Events	= new FCKEvents( FCK ) ;
+
+// DEPRECATED in favor or "GetData".
+FCK.GetHTML	= FCK.GetXHTML = FCK.GetData ;
+
+// DEPRECATED in favor of "SetData".
+FCK.SetHTML = FCK.SetData ;
+
+// InsertElementAndGetIt and CreateElement are Deprecated : returns the same value as InsertElement.
+FCK.InsertElementAndGetIt = FCK.CreateElement = FCK.InsertElement ;
+
+// Replace all events attributes (like onclick).
+function _FCK_ProtectEvents_ReplaceTags( tagMatch )
+{
+	return tagMatch.replace( FCKRegexLib.EventAttributes, _FCK_ProtectEvents_ReplaceEvents ) ;
+}
+
+// Replace an event attribute with its respective __fckprotectedatt attribute.
+// The original event markup will be encoded and saved as the value of the new
+// attribute.
+function _FCK_ProtectEvents_ReplaceEvents( eventMatch, attName )
+{
+	return ' ' + attName + '_fckprotectedatt="' + FCKTools.EncodeToHex( eventMatch ) + '"' ;
+}
+
+function _FCK_ProtectEvents_RestoreEvents( match, encodedOriginal )
+{
+	return FCKTools.DecodeHex( encodedOriginal ) ;
+}
+
+function _FCK_EditingArea_OnLoad()
+{
+	// Get the editor's window and document (DOM)
+	FCK.EditorWindow	= FCK.EditingArea.Window ;
+	FCK.EditorDocument	= FCK.EditingArea.Document ;
+
+	FCK.InitializeBehaviors() ;
+
+	// Create the enter key handler
+	if ( !FCKConfig.DisableEnterKeyHandler )
+		FCK.EnterKeyHandler = new FCKEnterKey( FCK.EditorWindow, FCKConfig.EnterMode, FCKConfig.ShiftEnterMode, FCKConfig.TabSpaces ) ;
+
+	// Listen for keystroke events.
+	FCK.KeystrokeHandler.AttachToElement( FCK.EditorDocument ) ;
+
+	if ( FCK._ForceResetIsDirty )
+		FCK.ResetIsDirty() ;
+
+	// This is a tricky thing for IE. In some cases, even if the cursor is
+	// blinking in the editing, the keystroke handler doesn't catch keyboard
+	// events. We must activate the editing area to make it work. (#142).
+	if ( FCKBrowserInfo.IsIE && FCK.HasFocus )
+		FCK.EditorDocument.body.setActive() ;
+
+	FCK.OnAfterSetHTML() ;
+
+	// Check if it is not a startup call, otherwise complete the startup.
+	if ( FCK.Status != FCK_STATUS_NOTLOADED )
+		return ;
+
+	FCK.SetStatus( FCK_STATUS_ACTIVE ) ;
+}
+
+function _FCK_GetEditorAreaStyleTags()
+{
+	var sTags = '' ;
+	var aCSSs = FCKConfig.EditorAreaCSS ;
+	var sStyles = FCKConfig.EditorAreaStyles ;
+
+	for ( var i = 0 ; i < aCSSs.length ; i++ )
+		sTags += '<link href="' + aCSSs[i] + '" rel="stylesheet" type="text/css" />' ;
+
+	if ( sStyles && sStyles.length > 0 )
+		sTags += "<style>" + sStyles + "</style>" ;
+
+	return sTags ;
+}
+
+function _FCK_KeystrokeHandler_OnKeystroke( keystroke, keystrokeValue )
+{
+	if ( FCK.Status != FCK_STATUS_COMPLETE )
+		return false ;
+
+	if ( FCK.EditMode == FCK_EDITMODE_WYSIWYG )
+	{
+		switch ( keystrokeValue )
+		{
+			case 'Paste' :
+				return !FCK.Events.FireEvent( 'OnPaste' ) ;
+
+			case 'Cut' :
+				FCKUndo.SaveUndoStep() ;
+				return false ;
+		}
+	}
+	else
+	{
+		// In source mode, some actions must have their default behavior.
+		if ( keystrokeValue.Equals( 'Paste', 'Undo', 'Redo', 'SelectAll' ) )
+			return false ;
 	}
 
@@ -967,2 +973,3 @@
 	}
 }
+
