Index: _source/plugins/link/dialogs/anchor.js
===================================================================
--- _source/plugins/link/dialogs/anchor.js	(revision 5985)
+++ _source/plugins/link/dialogs/anchor.js	(working copy)
@@ -26,9 +26,15 @@
 		{
 			// Always create a new anchor, because of IE BUG.
 			var name = this.getValueOf( 'info', 'txtName' ),
-				element = CKEDITOR.env.ie ?
-				editor.document.createElement( '<a name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) :
-				editor.document.createElement( 'a' );
+				element = CKEDITOR.env.ie6Compat ?
+					editor.document.createElement( '<a name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) :
+					editor.document.createElement( 'a' ),
+				fakeElement,
+				selection,
+				ranges,
+				tmpId,
+				style,
+				created;
 
 			// Move contents and attributes of old anchor to new anchor.
 			if ( this.editMode )
@@ -36,31 +42,62 @@
 				this.editObj.copyAttributes( element, { name : 1 } );
 				this.editObj.moveChildren( element );
 			}
+			else
+			{
+				// Put selected text inside the anchor
+				selection = editor.getSelection();
+				ranges = selection.getRanges( true );
+				if ( ranges.length == 1 && !ranges[0].collapsed )
+				{
+					tmpId = 'tmp' + CKEDITOR.tools.getNextNumber();
+					style = new CKEDITOR.style( { element : 'a', attributes : {'id': tmpId} } );
+					style.type = CKEDITOR.STYLE_INLINE;
+					style.apply( editor.document );
+					created = editor.document.getById( tmpId );
+					created.moveChildren( element );
 
+					selection.selectElement( created );
+				}
+			}
+
 			// Set name.
 			element.removeAttribute( '_cke_saved_name' );
 			element.setAttribute( 'name', name );
 
-			// Insert a new anchor.
-			var fakeElement = editor.createFakeElement( element, 'cke_anchor', 'anchor' );
-			if ( !this.editMode )
-				editor.insertElement( fakeElement );
+			if ( element.$.childNodes.length==0 && ( !CKEDITOR.env.gecko ) )
+			{
+				fakeElement = editor.createFakeElement( element, 'cke_anchor', 'anchor' );
+				// Insert a new anchor.
+				if ( !this.editMode )
+					editor.insertElement( fakeElement );
+				else
+				{
+					fakeElement.replace( this.fakeObj );
+					editor.getSelection().selectElement( fakeElement );
+				}
+			}
 			else
 			{
-				fakeElement.replace( this.fakeObj );
-				editor.getSelection().selectElement( fakeElement );
+				element.addClass( 'cke_anchor' );
+				if ( !this.editMode )
+					editor.insertElement( element );
+				else
+				{
+					element.replace( this.editObj );
+					editor.getSelection().selectElement( element );
+				}
 			}
 
 			return true;
 		},
 		onShow : function()
 		{
-			this.editObj = false;
-			this.fakeObj = false;
-			this.editMode = false;
+			this.editObj = this.fakeObj = this.editMode = false;
 
-			var selection = editor.getSelection();
-			var element = selection.getSelectedElement();
+			var selection = editor.getSelection(),
+				element = selection.getSelectedElement(),
+				link;
+
 			if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
 			{
 				this.fakeObj = element;
@@ -68,6 +105,16 @@
 				loadElements.apply( this, [ editor, selection, element ] );
 				selection.selectElement( this.fakeObj );
 			}
+			else
+			{
+				link = CKEDITOR.plugins.link.getSelectedLink( editor );
+				if ( link )
+				{
+					element = link;
+					loadElements.apply( this, [ editor, selection, element ] );
+					selection.selectElement( link );
+				}
+			}
 			this.getContentElement( 'info', 'txtName' ).focus();
 		},
 		contents : [
Index: _source/plugins/link/plugin.js
===================================================================
--- _source/plugins/link/plugin.js	(revision 5985)
+++ _source/plugins/link/plugin.js	(working copy)
@@ -30,24 +30,27 @@
 		CKEDITOR.dialog.add( 'anchor', this.path + 'dialogs/anchor.js' );
 
 		// Add the CSS styles for anchor placeholders.
+		var background = 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' +
+				'background-repeat: no-repeat;' +
+				'border: 1px solid #a9a9a9;',
+			anchorCss = '{' +
+				background +
+				'background-position: 0 center;' +
+				'padding-left: 18px;' +
+			'}';
+
 		editor.addCss(
 			'img.cke_anchor' +
 			'{' +
-				'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' +
+				background +
 				'background-position: center center;' +
-				'background-repeat: no-repeat;' +
-				'border: 1px solid #a9a9a9;' +
 				'width: 18px !important;' +
 				'height: 18px !important;' +
 			'}\n' +
 			'a.cke_anchor' +
-			'{' +
-				'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' +
-				'background-position: 0 center;' +
-				'background-repeat: no-repeat;' +
-				'border: 1px solid #a9a9a9;' +
-				'padding-left: 18px;' +
-			'}'
+			anchorCss +
+			'a[name]' +
+			anchorCss
 		   	);
 
 		// Register selection change handler for the unlink button.
@@ -137,7 +140,7 @@
 		var dataProcessor = editor.dataProcessor,
 			dataFilter = dataProcessor && dataProcessor.dataFilter;
 
-		if ( dataFilter )
+		if ( dataFilter && ( !CKEDITOR.env.gecko ) )
 		{
 			dataFilter.addRules(
 				{
@@ -147,7 +150,11 @@
 						{
 							var attributes = element.attributes;
 							if ( attributes.name && !attributes.href )
-								return editor.createFakeParserElement( element, 'cke_anchor', 'anchor' );
+							{
+								if (element.children.length==0)
+									return editor.createFakeParserElement( element, 'cke_anchor', 'anchor' );
+								attributes['class'] = (attributes['class'] || '') + ' cke_anchor';
+							}
 						}
 					}
 				});

