From 3c65da7e737a23b99d354b160f665e4c47d35876 Mon Sep 17 00:00:00 2001 From: Alex Monk Date: Sun, 4 May 2014 02:24:33 +0000 Subject: [PATCH] Revert "jquery.textSelection: Remove hardcoded checks for removed WikiEditor iframe mode" Appears to have broken CodeEditor This reverts commit c40b6fa9b0a0e17729a75661f80e7882cb0598e1. Change-Id: I6d04cb91527defe1fdb0d7fb2a324fe1417a89f7 --- resources/src/jquery/jquery.textSelection.js | 29 ++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/resources/src/jquery/jquery.textSelection.js b/resources/src/jquery/jquery.textSelection.js index 76e9601001..042db91cdc 100644 --- a/resources/src/jquery/jquery.textSelection.js +++ b/resources/src/jquery/jquery.textSelection.js @@ -24,6 +24,9 @@ $.fn.textSelection = function ( command, options ) { var fn, + context, + hasIframe, + needSave, retval; /** @@ -146,6 +149,9 @@ // See bug 35201. activateElementOnIE( this ); + if ( context ) { + context.fn.restoreCursorAndScrollTop(); + } if ( options.selectionStart !== undefined ) { $( this ).textSelection( 'setSelection', { 'start': options.selectionStart, 'end': options.selectionEnd } ); } @@ -525,12 +531,19 @@ // Position to start selection at start: undefined, // Position to end selection at. Defaults to start - end: undefined + end: undefined, + // Element to start selection in (iframe only) + startContainer: undefined, + // Element to end selection in (iframe only). Defaults to startContainer + endContainer: undefined }, options ); if ( options.end === undefined ) { options.end = options.start; } + if ( options.endContainer === undefined ) { + options.endContainer = options.startContainer; + } // FIXME: We may not need character position-based functions if we insert markers in the right places break; case 'scrollToCaretPosition': @@ -540,7 +553,19 @@ break; } - retval = fn[command].call( this, options ); + context = $( this ).data( 'wikiEditor-context' ); + hasIframe = context !== undefined && context && context.$iframe !== undefined; + + // IE selection restore voodoo + needSave = false; + if ( hasIframe && context.savedSelection !== null ) { + context.fn.restoreSelection(); + needSave = true; + } + retval = ( hasIframe ? context.fn : fn )[command].call( this, options ); + if ( hasIframe && needSave ) { + context.fn.saveSelection(); + } return retval; }; -- 2.20.1