Index: /CKEditor/trunk/_source/plugins/selection/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/selection/plugin.js	(revision 5631)
+++ /CKEditor/trunk/_source/plugins/selection/plugin.js	(revision 5632)
@@ -476,4 +476,13 @@
 				},
 
+		/**
+		 * Retrieve the {@link CKEDITOR.dom.range} instances that represent the current selection.
+		 * Note: Some browsers returns multiple ranges even on a sequent selection, e.g. Firefox returns
+		 * one range for each table cell when one or more table row is selected.
+		 * @return {Array}
+		 * @example
+		 * var ranges = selection.getRanges();
+		 * alert(ranges.length);
+		 */
 		getRanges :
 			CKEDITOR.env.ie ?
@@ -837,4 +846,8 @@
 		},
 
+		/**
+		 *  Make the current selection of type {@link CKEDITOR.SELECTION_ELEMENT} by enclosing the specified element.
+		 * @param element
+		 */
 		selectElement : function( element )
 		{
@@ -893,4 +906,9 @@
 		},
 
+		/**
+		 *  Adding the specified ranges to document selection preceding
+		 * by clearing up the original selection.
+		 * @param {CKEDITOR.dom.range} ranges
+		 */
 		selectRanges : function( ranges )
 		{
@@ -947,4 +965,10 @@
 		},
 
+		/**
+		 *  Create bookmark for every single of this selection range (from #getRanges)
+		 * by calling the {@link CKEDITOR.dom.range.prototype.createBookmark} method,
+		 * with extra cares to avoid interferon among those ranges. Same arguments are
+		 * received as with the underlay range method.
+		 */
 		createBookmarks : function( serializable )
 		{
@@ -979,4 +1003,10 @@
 		},
 
+		/**
+		 *  Create bookmark for every single of this selection range (from #getRanges)
+		 * by calling the {@link CKEDITOR.dom.range.prototype.createBookmark2} method,
+		 * with extra cares to avoid interferon among those ranges. Same arguments are
+		 * received as with the underlay range method.
+		 */
 		createBookmarks2 : function( normalized )
 		{
@@ -990,4 +1020,8 @@
 		},
 
+		/**
+		 * Select the virtual ranges denote by the bookmarks by calling #selectRanges.
+		 * @param bookmarks
+		 */
 		selectBookmarks : function( bookmarks )
 		{
@@ -1003,4 +1037,7 @@
 		},
 
+		/**
+		 * Retrieve the common ancestor node of the first range and the last range.
+		 */
 		getCommonAncestor : function()
 		{
@@ -1011,5 +1048,7 @@
 		},
 
-		// Moving scroll bar to the current selection's start position.
+		/**
+		 * Moving scroll bar to the current selection's start position.
+		 */
 		scrollIntoView : function()
 		{
@@ -1021,149 +1060,150 @@
 	};
 })();
+
 ( function()
 {
-var notWhitespaces = CKEDITOR.dom.walker.whitespaces( true );
-var fillerTextRegex = /\ufeff|\u00a0/;
-var nonCells = { table:1,tbody:1,tr:1 };
-
-CKEDITOR.dom.range.prototype.select =
-	CKEDITOR.env.ie ?
-		// V2
-		function( forceExpand )
-		{
-			var collapsed = this.collapsed;
-			var isStartMarkerAlone;
-			var dummySpan;
-
-			// IE doesn't support selecting the entire table row/cell, move the selection into cells, e.g.
-			// <table><tbody><tr>[<td>cell</b></td>... => <table><tbody><tr><td>[cell</td>...
-			if ( this.startContainer.type == CKEDITOR.NODE_ELEMENT && this.startContainer.getName() in nonCells
-				|| this.endContainer.type == CKEDITOR.NODE_ELEMENT && this.endContainer.getName() in nonCells )
-			{
-				this.shrink( CKEDITOR.NODE_ELEMENT, true );
-			}
-
-			var bookmark = this.createBookmark();
-
-			// Create marker tags for the start and end boundaries.
-			var startNode = bookmark.startNode;
-
-			var endNode;
-			if ( !collapsed )
-				endNode = bookmark.endNode;
-
-			// Create the main range which will be used for the selection.
-			var ieRange = this.document.$.body.createTextRange();
-
-			// Position the range at the start boundary.
-			ieRange.moveToElementText( startNode.$ );
-			ieRange.moveStart( 'character', 1 );
-
-			if ( endNode )
-			{
-				// Create a tool range for the end.
-				var ieRangeEnd = this.document.$.body.createTextRange();
-
-				// Position the tool range at the end.
-				ieRangeEnd.moveToElementText( endNode.$ );
-
-				// Move the end boundary of the main range to match the tool range.
-				ieRange.setEndPoint( 'EndToEnd', ieRangeEnd );
-				ieRange.moveEnd( 'character', -1 );
-			}
-			else
-			{
-				// The isStartMarkerAlone logic comes from V2. It guarantees that the lines
-				// will expand and that the cursor will be blinking on the right place.
-				// Actually, we are using this flag just to avoid using this hack in all
-				// situations, but just on those needed.
-				var next = startNode.getNext( notWhitespaces );
-				isStartMarkerAlone = ( !( next && next.getText && next.getText().match( fillerTextRegex ) )     // already a filler there?
-									  && ( forceExpand || !startNode.hasPrevious() || ( startNode.getPrevious().is && startNode.getPrevious().is( 'br' ) ) ) );
-
-				// Append a temporary <span>&#65279;</span> before the selection.
-				// This is needed to avoid IE destroying selections inside empty
-				// inline elements, like <b></b> (#253).
-				// It is also needed when placing the selection right after an inline
-				// element to avoid the selection moving inside of it.
-				dummySpan = this.document.createElement( 'span' );
-				dummySpan.setHtml( '&#65279;' );	// Zero Width No-Break Space (U+FEFF). See #1359.
-				dummySpan.insertBefore( startNode );
-
-				if ( isStartMarkerAlone )
-				{
-					// To expand empty blocks or line spaces after <br>, we need
-					// instead to have any char, which will be later deleted using the
-					// selection.
-					// \ufeff = Zero Width No-Break Space (U+FEFF). (#1359)
-					this.document.createText( '\ufeff' ).insertBefore( startNode );
-				}
-			}
-
-			// Remove the markers (reset the position, because of the changes in the DOM tree).
-			this.setStartBefore( startNode );
-			startNode.remove();
-
-			if ( collapsed )
-			{
-				if ( isStartMarkerAlone )
-				{
-					// Move the selection start to include the temporary \ufeff.
-					ieRange.moveStart( 'character', -1 );
-
+	var notWhitespaces = CKEDITOR.dom.walker.whitespaces( true ),
+			fillerTextRegex = /\ufeff|\u00a0/,
+			nonCells = { table:1,tbody:1,tr:1 };
+
+	CKEDITOR.dom.range.prototype.select =
+		CKEDITOR.env.ie ?
+			// V2
+			function( forceExpand )
+			{
+				var collapsed = this.collapsed;
+				var isStartMarkerAlone;
+				var dummySpan;
+
+				// IE doesn't support selecting the entire table row/cell, move the selection into cells, e.g.
+				// <table><tbody><tr>[<td>cell</b></td>... => <table><tbody><tr><td>[cell</td>...
+				if ( this.startContainer.type == CKEDITOR.NODE_ELEMENT && this.startContainer.getName() in nonCells
+					|| this.endContainer.type == CKEDITOR.NODE_ELEMENT && this.endContainer.getName() in nonCells )
+				{
+					this.shrink( CKEDITOR.NODE_ELEMENT, true );
+				}
+
+				var bookmark = this.createBookmark();
+
+				// Create marker tags for the start and end boundaries.
+				var startNode = bookmark.startNode;
+
+				var endNode;
+				if ( !collapsed )
+					endNode = bookmark.endNode;
+
+				// Create the main range which will be used for the selection.
+				var ieRange = this.document.$.body.createTextRange();
+
+				// Position the range at the start boundary.
+				ieRange.moveToElementText( startNode.$ );
+				ieRange.moveStart( 'character', 1 );
+
+				if ( endNode )
+				{
+					// Create a tool range for the end.
+					var ieRangeEnd = this.document.$.body.createTextRange();
+
+					// Position the tool range at the end.
+					ieRangeEnd.moveToElementText( endNode.$ );
+
+					// Move the end boundary of the main range to match the tool range.
+					ieRange.setEndPoint( 'EndToEnd', ieRangeEnd );
+					ieRange.moveEnd( 'character', -1 );
+				}
+				else
+				{
+					// The isStartMarkerAlone logic comes from V2. It guarantees that the lines
+					// will expand and that the cursor will be blinking on the right place.
+					// Actually, we are using this flag just to avoid using this hack in all
+					// situations, but just on those needed.
+					var next = startNode.getNext( notWhitespaces );
+					isStartMarkerAlone = ( !( next && next.getText && next.getText().match( fillerTextRegex ) )     // already a filler there?
+										  && ( forceExpand || !startNode.hasPrevious() || ( startNode.getPrevious().is && startNode.getPrevious().is( 'br' ) ) ) );
+
+					// Append a temporary <span>&#65279;</span> before the selection.
+					// This is needed to avoid IE destroying selections inside empty
+					// inline elements, like <b></b> (#253).
+					// It is also needed when placing the selection right after an inline
+					// element to avoid the selection moving inside of it.
+					dummySpan = this.document.createElement( 'span' );
+					dummySpan.setHtml( '&#65279;' );	// Zero Width No-Break Space (U+FEFF). See #1359.
+					dummySpan.insertBefore( startNode );
+
+					if ( isStartMarkerAlone )
+					{
+						// To expand empty blocks or line spaces after <br>, we need
+						// instead to have any char, which will be later deleted using the
+						// selection.
+						// \ufeff = Zero Width No-Break Space (U+FEFF). (#1359)
+						this.document.createText( '\ufeff' ).insertBefore( startNode );
+					}
+				}
+
+				// Remove the markers (reset the position, because of the changes in the DOM tree).
+				this.setStartBefore( startNode );
+				startNode.remove();
+
+				if ( collapsed )
+				{
+					if ( isStartMarkerAlone )
+					{
+						// Move the selection start to include the temporary \ufeff.
+						ieRange.moveStart( 'character', -1 );
+
+						ieRange.select();
+
+						// Remove our temporary stuff.
+						this.document.$.selection.clear();
+					}
+					else
+						ieRange.select();
+
+					this.moveToPosition( dummySpan, CKEDITOR.POSITION_BEFORE_START );
+					dummySpan.remove();
+				}
+				else
+				{
+					this.setEndBefore( endNode );
+					endNode.remove();
 					ieRange.select();
-
-					// Remove our temporary stuff.
-					this.document.$.selection.clear();
-				}
-				else
-					ieRange.select();
-
-				this.moveToPosition( dummySpan, CKEDITOR.POSITION_BEFORE_START );
-				dummySpan.remove();
-			}
-			else
-			{
-				this.setEndBefore( endNode );
-				endNode.remove();
-				ieRange.select();
-			}
-
-			this.document.fire( 'selectionchange' );
-		}
-	:
-		function()
-		{
-			var startContainer = this.startContainer;
-
-			// If we have a collapsed range, inside an empty element, we must add
-			// something to it, otherwise the caret will not be visible.
-			if ( this.collapsed && startContainer.type == CKEDITOR.NODE_ELEMENT && !startContainer.getChildCount() )
-				startContainer.append( new CKEDITOR.dom.text( '' ) );
-
-			var nativeRange = this.document.$.createRange();
-			nativeRange.setStart( startContainer.$, this.startOffset );
-
-			try
-			{
-				nativeRange.setEnd( this.endContainer.$, this.endOffset );
-			}
-			catch ( e )
-			{
-				// There is a bug in Firefox implementation (it would be too easy
-				// otherwise). The new start can't be after the end (W3C says it can).
-				// So, let's create a new range and collapse it to the desired point.
-				if ( e.toString().indexOf( 'NS_ERROR_ILLEGAL_VALUE' ) >= 0 )
-				{
-					this.collapse( true );
+				}
+
+				this.document.fire( 'selectionchange' );
+			}
+		:
+			function()
+			{
+				var startContainer = this.startContainer;
+
+				// If we have a collapsed range, inside an empty element, we must add
+				// something to it, otherwise the caret will not be visible.
+				if ( this.collapsed && startContainer.type == CKEDITOR.NODE_ELEMENT && !startContainer.getChildCount() )
+					startContainer.append( new CKEDITOR.dom.text( '' ) );
+
+				var nativeRange = this.document.$.createRange();
+				nativeRange.setStart( startContainer.$, this.startOffset );
+
+				try
+				{
 					nativeRange.setEnd( this.endContainer.$, this.endOffset );
 				}
-				else
-					throw( e );
-			}
-
-			var selection = this.document.getSelection().getNative();
-			selection.removeAllRanges();
-			selection.addRange( nativeRange );
-		};
+				catch ( e )
+				{
+					// There is a bug in Firefox implementation (it would be too easy
+					// otherwise). The new start can't be after the end (W3C says it can).
+					// So, let's create a new range and collapse it to the desired point.
+					if ( e.toString().indexOf( 'NS_ERROR_ILLEGAL_VALUE' ) >= 0 )
+					{
+						this.collapse( true );
+						nativeRange.setEnd( this.endContainer.$, this.endOffset );
+					}
+					else
+						throw( e );
+				}
+
+				var selection = this.document.getSelection().getNative();
+				selection.removeAllRanges();
+				selection.addRange( nativeRange );
+			};
 } )();
