+ /**
+ * Replace the selected text in the textarea with the given text, or insert it at the cursor.
+ *
+ * @private
+ * @param {string} value
+ * @return {jQuery}
+ * @chainable
+ */
+ replaceSelection: function ( value ) {
+ return this.each( function () {
+ var allText, currSelection, startPos, endPos;
+
+ allText = $( this ).textSelection( 'getContents' );
+ currSelection = $( this ).textSelection( 'getCaretPosition', { startAndEnd: true } );
+ startPos = currSelection[ 0 ];
+ endPos = currSelection[ 1 ];
+
+ $( this ).textSelection( 'setContents', allText.slice( 0, startPos ) + value +
+ allText.slice( endPos ) );
+ $( this ).textSelection( 'setSelection', {
+ start: startPos,
+ end: startPos + value.length
+ } );
+ } );
+ },
+