Index: CKEditor/trunk/CHANGES.html
===================================================================
--- CKEditor/trunk/CHANGES.html	(revision 5303)
+++ CKEditor/trunk/CHANGES.html	(revision 5304)
@@ -107,4 +107,5 @@
 		<li><a href="http://dev.fckeditor.net/ticket/5363">#5363</a> : 'title' attribute now presents on all editor iframes.</li>
 		<li><a href="http://dev.fckeditor.net/ticket/5374">#5374</a> : Unable to toggle inline style when selection start from the linefeed of the previous paragraph.</li>
+		<li><a href="http://dev.fckeditor.net/ticket/4513">#4513</a> : Selected link element is not always correctly detected when using keyboard arrows to perform such selection.</li>
 		<li>Updated the following language files:<ul>
 			<li>Faroese;</li>
Index: CKEditor/trunk/_source/plugins/link/dialogs/link.js
===================================================================
--- CKEditor/trunk/_source/plugins/link/dialogs/link.js	(revision 5303)
+++ CKEditor/trunk/_source/plugins/link/dialogs/link.js	(revision 5304)
@@ -6,4 +6,5 @@
 CKEDITOR.dialog.add( 'link', function( editor )
 {
+	var plugin = CKEDITOR.plugins.link;
 	// Handles the event when the "Target" selection box is changed.
 	var targetChanged = function()
@@ -94,5 +95,5 @@
 	var parseLink = function( editor, element )
 	{
-		var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) : '',
+		var href = ( element  && ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) ) || '',
 		 	javascriptMatch,
 			emailMatch,
@@ -1137,28 +1138,19 @@
 			var editor = this.getParentEditor(),
 				selection = editor.getSelection(),
-				ranges = selection.getRanges(),
-				element = null,
-				me = this;
+				element = null;
+
 			// Fill in all the relevant fields if there's already one link selected.
-			if ( ranges.length == 1 )
-			{
-
-				var rangeRoot = ranges[0].getCommonAncestor( true );
-				element = rangeRoot.getAscendant( 'a', true );
-				if ( element && element.getAttribute( 'href' ) )
-				{
-					selection.selectElement( element );
-				}
-				else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) &&
-						 element.getAttribute( '_cke_real_element_type' ) &&
-						 element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
-				{
-					this.fakeObj = element;
-					element = editor.restoreRealElement( this.fakeObj );
-					selection.selectElement( this.fakeObj );
-				}
-				else
-					element = null;
-			}
+			if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) )
+				selection.selectElement( element );
+			else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' )
+					&& element.getAttribute( '_cke_real_element_type' )
+					&& element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
+			{
+				this.fakeObj = element;
+				element = editor.restoreRealElement( this.fakeObj );
+				selection.selectElement( this.fakeObj );
+			}
+			else
+				element = null;
 
 			this.setupContent( parseLink.apply( this, [ editor, element ] ) );
Index: CKEditor/trunk/_source/plugins/link/plugin.js
===================================================================
--- CKEditor/trunk/_source/plugins/link/plugin.js	(revision 5303)
+++ CKEditor/trunk/_source/plugins/link/plugin.js	(revision 5304)
@@ -108,5 +108,5 @@
 					if ( !isAnchor )
 					{
-						if ( !( element = element.getAscendant( 'a', true ) ) )
+						if ( !( element = CKEDITOR.plugins.link.getSelectedLink( editor ) ) )
 							return null;
 
@@ -147,4 +147,33 @@
 	requires : [ 'fakeobjects' ]
 } );
+
+CKEDITOR.plugins.link =
+{
+	/**
+	 *  Get the surrounding link element of current selection.
+	 * @param editor
+	 * @example CKEDITOR.plugins.link.getSelectedLink( editor );
+	 * @since 3.2.1
+	 * The following selection will all return the link element.   
+	 *	 <pre>
+	 *  <a href="#">li^nk</a>
+	 *  <a href="#">[link]</a>
+	 *  text[<a href="#">link]</a>
+	 *  <a href="#">li[nk</a>]
+	 *  [<b><a href="#">li]nk</a></b>]
+	 *  [<a href="#"><b>li]nk</b></a>
+	 * </pre>
+	 */
+	getSelectedLink : function( editor )
+	{
+		var range;
+		try { range  = editor.getSelection().getRanges()[ 0 ]; }
+		catch( e ) { return null; }
+
+		range.shrink( CKEDITOR.SHRINK_TEXT );
+		var root = range.getCommonAncestor();
+		return root.getAscendant( 'a', true );
+	}
+};
 
 CKEDITOR.unlinkCommand = function(){};
