Index: /FCKeditor/trunk/_whatsnew.html
===================================================================
--- /FCKeditor/trunk/_whatsnew.html	(revision 340)
+++ /FCKeditor/trunk/_whatsnew.html	(revision 341)
@@ -117,4 +117,8 @@
 			with dimensions set as styles was opened with the image manager and then the dialog was
 			canceled the dimensions in the style were lost.</li>
+		<li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/220">#220</a>] The creation
+			of links or anchors in a selection that results on more than a single link created
+			will not anymore leave temporary links in the source. All links will be defined
+			as expected.</li>
 	</ul>
 	<h3>
Index: /FCKeditor/trunk/editor/_source/internals/fck_gecko.js
===================================================================
--- /FCKeditor/trunk/editor/_source/internals/fck_gecko.js	(revision 340)
+++ /FCKeditor/trunk/editor/_source/internals/fck_gecko.js	(revision 341)
@@ -208,4 +208,7 @@
 FCK.CreateLink = function( url )
 {
+	// Creates the array that will be returned. It contains one or more created links (see #220).
+	var aCreatedLinks = new Array() ;
+
 	FCK.ExecuteNamedCommand( 'Unlink' ) ;
 
@@ -218,14 +221,16 @@
 		FCK.ExecuteNamedCommand( 'CreateLink', sTempUrl ) ;
 
-		// Retrieve the just created link using XPath.
-		var oLink = this.EditorDocument.evaluate("//a[@href='" + sTempUrl + "']", this.EditorDocument.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ;
-
-		if ( oLink )
+		// Retrieve the just created links using XPath.
+		var oLinksInteractor = this.EditorDocument.evaluate("//a[@href='" + sTempUrl + "']", this.EditorDocument.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null) ;
+
+		// Add all links to the returning array.
+		for ( var i = 0 ; i < oLinksInteractor.snapshotLength ; i++ )
 		{
+			var oLink = oLinksInteractor.snapshotItem( i ) ;
 			oLink.href = url ;
-			return oLink ;
+			aCreatedLinks.push( oLink ) ;
 		}
 	}
 
-	return null ;
-}
+	return aCreatedLinks ;
+}
Index: /FCKeditor/trunk/editor/_source/internals/fck_ie.js
===================================================================
--- /FCKeditor/trunk/editor/_source/internals/fck_ie.js	(revision 340)
+++ /FCKeditor/trunk/editor/_source/internals/fck_ie.js	(revision 341)
@@ -349,4 +349,7 @@
 FCK.CreateLink = function( url )
 {
+	// Creates the array that will be returned. It contains one or more created links (see #220).
+	var aCreatedLinks = new Array() ;
+
 	// Remove any existing link in the selection.
 	FCK.ExecuteNamedCommand( 'Unlink' ) ;
@@ -370,5 +373,5 @@
 			oLink.appendChild( oControl ) ;
 			
-			return oLink ;
+			return [ oLink ] ;
 		}
 
@@ -402,9 +405,9 @@
 				}
 
-				return oLink ;
+				aCreatedLinks.push( oLink ) ;
 			}
 		}
 	}
 
-	return null ;
-}
+	return aCreatedLinks ;
+}
Index: /FCKeditor/trunk/editor/dialog/fck_anchor.html
===================================================================
--- /FCKeditor/trunk/editor/dialog/fck_anchor.html	(revision 340)
+++ /FCKeditor/trunk/editor/dialog/fck_anchor.html	(revision 341)
@@ -111,37 +111,46 @@
 
 	// Create a new anchor preserving the current selection
-	oAnchor = oEditor.FCK.CreateLink( '#' ) ;
-	if ( !oAnchor )
+	var aNewAnchors = oEditor.FCK.CreateLink( '#' ) ;
+
+	if ( aNewAnchors.length == 0 )
 	{
 		// Nothing was selected, so now just create a normal A
-		oAnchor = oEditor.FCK.InsertElement( 'a' ) ;
+		aNewAnchors.push( oEditor.FCK.InsertElement( 'a' ) ) ;
 	}
 	else
 	{
 		// Remove the fake href
-		oAnchor.removeAttribute( 'href' ) ;
-	}
-	// Set the name
-	oAnchor.name = sNewName ;
-
-	// IE does require special processing to show the Anchor's image
-	// Opera doesn't allow to select empty anchors
-	if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera )
-	{
-		if ( oAnchor.innerHTML != '' )
+		for ( var i = 0 ; i < aNewAnchors.length ; i++ )
+			aNewAnchors[i].removeAttribute( 'href' ) ;
+	}
+
+	// More than one anchors may have been created, so interact through all of them (see #220).
+	for ( var i = 0 ; i < aNewAnchors.length ; i++ )
+	{
+		oAnchor = aNewAnchors[i] ;
+
+		// Set the name
+		oAnchor.name = sNewName ;
+
+		// IE does require special processing to show the Anchor's image
+		// Opera doesn't allow to select empty anchors
+		if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera )
 		{
-			if ( FCKBrowserInfo.IsIE )
-				oAnchor.className += ' FCK__AnchorC' ;
+			if ( oAnchor.innerHTML != '' )
+			{
+				if ( FCKBrowserInfo.IsIE )
+					oAnchor.className += ' FCK__AnchorC' ;
+			}
+			else
+			{
+				// Create a fake image for both IE and Opera
+				var oImg = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oAnchor.cloneNode(true) ) ;
+				oImg.setAttribute( '_fckanchor', 'true', 0 ) ;
+
+				oAnchor.parentNode.insertBefore( oImg, oAnchor ) ;
+				oAnchor.parentNode.removeChild( oAnchor ) ;
+			}
+
 		}
-		else
-		{
-			// Create a fake image for both IE and Opera
-			var oImg = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oAnchor.cloneNode(true) ) ;
-			oImg.setAttribute( '_fckanchor', 'true', 0 ) ;
-
-			oAnchor.parentNode.insertBefore( oImg, oAnchor ) ;
-			oAnchor.parentNode.removeChild( oAnchor ) ;
-		}
-
 	}
 
Index: /FCKeditor/trunk/editor/dialog/fck_image/fck_image.js
===================================================================
--- /FCKeditor/trunk/editor/dialog/fck_image/fck_image.js	(revision 340)
+++ /FCKeditor/trunk/editor/dialog/fck_image/fck_image.js	(revision 341)
@@ -251,5 +251,5 @@
 				oEditor.FCKSelection.SelectNode( oImage ) ;
 
-			oLink = oEditor.FCK.CreateLink( sLnkUrl ) ;
+			oLink = oEditor.FCK.CreateLink( sLnkUrl )[0] ;
 
 			if ( !bHasImage )
Index: /FCKeditor/trunk/editor/dialog/fck_link/fck_link.js
===================================================================
--- /FCKeditor/trunk/editor/dialog/fck_link/fck_link.js	(revision 340)
+++ /FCKeditor/trunk/editor/dialog/fck_link/fck_link.js	(revision 341)
@@ -503,14 +503,11 @@
 	}
 
-	// No link selected, so try to create one.
-	if ( !oLink )
-		oLink = oEditor.FCK.CreateLink( sUri ) ;
-
-	if ( oLink )
-		sInnerHtml = oLink.innerHTML ;		// Save the innerHTML (IE changes it if it is like an URL).
-	else
-	{
-		// If no selection, use the uri as the link text (by dom, 2006-05-26)
-
+	// If no link is selected, create a new one (it may result in more than one link creation - #220).
+	var aLinks = oLink ? [ oLink ] : oEditor.FCK.CreateLink( sUri ) ;
+
+	// If no selection, no links are created, so use the uri as the link text (by dom, 2006-05-26)
+	var aHasSelection = ( aLinks.length > 0 ) ;
+	if ( !aHasSelection )
+	{
 		sInnerHtml = sUri;
 
@@ -538,63 +535,74 @@
 
 		// Create a new (empty) anchor.
-		oLink = oEditor.FCK.InsertElement( 'a' ) ;
+		aLinks = [ oEditor.FCK.InsertElement( 'a' ) ] ;
 	}
 
 	oEditor.FCKUndo.SaveUndoStep() ;
 
-	oLink.href = sUri ;
-	SetAttribute( oLink, '_fcksavedurl', sUri ) ;
-
-	// Accesible popups
-	if( GetE('cmbTarget').value == 'popup' )
-	{
-		SetAttribute( oLink, 'onclick_fckprotectedatt', " onclick=\"" + BuildOnClickPopup() + "\"") ;
-	}
-	else
-	{
-		// Check if the previous onclick was for a popup:
-		// In that case remove the onclick handler.
-		var onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ;
-		if( oRegex.OnClickPopup.test( onclick ) )
-			SetAttribute( oLink, 'onclick_fckprotectedatt', '' ) ;
-	}
-
-	oLink.innerHTML = sInnerHtml ;		// Set (or restore) the innerHTML
-
-	// Target
-	if( GetE('cmbTarget').value != 'popup' )
-		SetAttribute( oLink, 'target', GetE('txtTargetFrame').value ) ;
-	else
-		SetAttribute( oLink, 'target', null ) ;
-
-	// Advances Attributes
-	SetAttribute( oLink, 'id'		, GetE('txtAttId').value ) ;
-	SetAttribute( oLink, 'name'		, GetE('txtAttName').value ) ;
-	SetAttribute( oLink, 'dir'		, GetE('cmbAttLangDir').value ) ;
-	SetAttribute( oLink, 'lang'		, GetE('txtAttLangCode').value ) ;
-	SetAttribute( oLink, 'accesskey', GetE('txtAttAccessKey').value ) ;
-	SetAttribute( oLink, 'tabindex'	, ( GetE('txtAttTabIndex').value > 0 ? GetE('txtAttTabIndex').value : null ) ) ;
-	SetAttribute( oLink, 'title'	, GetE('txtAttTitle').value ) ;
-	SetAttribute( oLink, 'type'		, GetE('txtAttContentType').value ) ;
-	SetAttribute( oLink, 'charset'	, GetE('txtAttCharSet').value ) ;
-
-	if ( oEditor.FCKBrowserInfo.IsIE )
-	{
-		var sClass = GetE('txtAttClasses').value ;
-		// If it's also an anchor add an internal class
-		if ( GetE('txtAttName').value.length != 0 )
-			sClass += ' FCK__AnchorC' ;
-		SetAttribute( oLink, 'className', sClass ) ;
-
-		oLink.style.cssText = GetE('txtAttStyle').value ;
-	}
-	else
-	{
-		SetAttribute( oLink, 'class', GetE('txtAttClasses').value ) ;
-		SetAttribute( oLink, 'style', GetE('txtAttStyle').value ) ;
-	}
-
-	// Select the link.
-	oEditor.FCKSelection.SelectNode(oLink);
+	for ( var i = 0 ; i < aLinks.length ; i++ )
+	{
+		oLink = aLinks[i] ;
+
+		if ( aHasSelection )
+			sInnerHtml = oLink.innerHTML ;		// Save the innerHTML (IE changes it if it is like an URL).
+
+		oLink.href = sUri ;
+		SetAttribute( oLink, '_fcksavedurl', sUri ) ;
+
+		// Accesible popups
+		if( GetE('cmbTarget').value == 'popup' )
+		{
+			SetAttribute( oLink, 'onclick_fckprotectedatt', " onclick=\"" + BuildOnClickPopup() + "\"") ;
+		}
+		else
+		{
+			// Check if the previous onclick was for a popup:
+			// In that case remove the onclick handler.
+			var onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ;
+			if( oRegex.OnClickPopup.test( onclick ) )
+				SetAttribute( oLink, 'onclick_fckprotectedatt', '' ) ;
+		}
+
+		oLink.innerHTML = sInnerHtml ;		// Set (or restore) the innerHTML
+
+		// Target
+		if( GetE('cmbTarget').value != 'popup' )
+			SetAttribute( oLink, 'target', GetE('txtTargetFrame').value ) ;
+		else
+			SetAttribute( oLink, 'target', null ) ;
+
+		// Let's set the "id" only for the first link to avoid duplication.
+		if ( i == 0 )
+			SetAttribute( oLink, 'id', GetE('txtAttId').value ) ;
+
+		// Advances Attributes
+		SetAttribute( oLink, 'name'		, GetE('txtAttName').value ) ;
+		SetAttribute( oLink, 'dir'		, GetE('cmbAttLangDir').value ) ;
+		SetAttribute( oLink, 'lang'		, GetE('txtAttLangCode').value ) ;
+		SetAttribute( oLink, 'accesskey', GetE('txtAttAccessKey').value ) ;
+		SetAttribute( oLink, 'tabindex'	, ( GetE('txtAttTabIndex').value > 0 ? GetE('txtAttTabIndex').value : null ) ) ;
+		SetAttribute( oLink, 'title'	, GetE('txtAttTitle').value ) ;
+		SetAttribute( oLink, 'type'		, GetE('txtAttContentType').value ) ;
+		SetAttribute( oLink, 'charset'	, GetE('txtAttCharSet').value ) ;
+
+		if ( oEditor.FCKBrowserInfo.IsIE )
+		{
+			var sClass = GetE('txtAttClasses').value ;
+			// If it's also an anchor add an internal class
+			if ( GetE('txtAttName').value.length != 0 )
+				sClass += ' FCK__AnchorC' ;
+			SetAttribute( oLink, 'className', sClass ) ;
+
+			oLink.style.cssText = GetE('txtAttStyle').value ;
+		}
+		else
+		{
+			SetAttribute( oLink, 'class', GetE('txtAttClasses').value ) ;
+			SetAttribute( oLink, 'style', GetE('txtAttStyle').value ) ;
+		}
+	}
+
+	// Select the (first) link.
+	oEditor.FCKSelection.SelectNode( aLinks[0] );
 
 	return true ;
