TheDJ has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/150037

Change subject: Split jquery.textSelection and WikiEditor api overrides
......................................................................

Split jquery.textSelection and WikiEditor api overrides

This depends on MediaWiki core change I14492572

Bug: 29328
Change-Id: I57bc7791dc61b7edcf258e6c16445d5a4a8783cf
---
M modules/jquery.codeEditor.js
1 file changed, 25 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CodeEditor 
refs/changes/37/150037/1

diff --git a/modules/jquery.codeEditor.js b/modules/jquery.codeEditor.js
index c7f46df..9cf7f70 100644
--- a/modules/jquery.codeEditor.js
+++ b/modules/jquery.codeEditor.js
@@ -39,7 +39,8 @@
        };
 
        $.wikiEditor.extensions.codeEditor = function ( context ) {
-               var saveAndExtend;
+               var saveAndExtend,
+                       textSelectionFn;
 
                /*
                 * Event Handlers
@@ -189,6 +190,7 @@
                                        // Load the editor now
                                        context.codeEditor = ace.edit( 
editdiv[0] );
                                        
context.codeEditor.getSession().setValue( box.val() );
+                                       box.textSelection( 'register', 
textSelectionFn );
 
                                        // Disable some annoying commands
                                        
context.codeEditor.commands.removeCommand( 'replace' );          // ctrl+R
@@ -203,16 +205,6 @@
                                                enableSnippets: true
                                        } );
 
-                                       // fakeout for bug 29328
-                                       context.$iframe = [
-                                               {
-                                                       contentWindow: {
-                                                               focus: function 
() {
-                                                                       
context.codeEditor.focus();
-                                                               }
-                                                       }
-                                               }
-                                       ];
                                        box.closest( 'form' ).submit( 
context.evt.codeEditorSubmit );
                                        session = 
context.codeEditor.getSession();
 
@@ -265,7 +257,8 @@
                                $( mw ).unbind( 'LivePreviewPrepare', 
context.evt.codeEditorSubmit ); // deprecated
 
                                // Save contents
-                               context.$textarea.val( context.fn.getContents() 
);
+                               context.$textarea.textSelection( 'unregister' );
+                               context.$textarea.val( 
textSelectionFn.getContents() );
 
                                // @todo fetch cursor, scroll position
 
@@ -273,7 +266,6 @@
                                context.fn.removeStatusBar();
                                context.$codeEditorContainer.remove();
                                context.$codeEditorContainer = undefined;
-                               context.$iframe = undefined;
                                context.codeEditor = undefined;
 
                                // Restore textarea
@@ -535,18 +527,26 @@
                                mw.log( 'codeEditor stub function 
restoreSelection called' );
                        },
 
+                       /**
+                        * Scroll an element to the top of the iframe
+                        *
+                        * @param $element jQuery object containing an element 
in the iframe
+                        * @param force If true, scroll the element even if 
it's already visible
+                        */
+                       'scrollToTop': function () {
+                               mw.log( 'codeEditor stub function scrollToTop 
called' );
+                       }
+               } );
+
+               /**
+                * Compatibility with the $.textSelection jQuery plug-in. When 
the iframe is in use, these functions provide
+                * equivalant functionality to the otherwise textarea-based 
functionality.
+                */
+               textSelectionFn = {
+
                        /* Needed for search/replace */
                        'getContents': function () {
                                return 
context.codeEditor.getSession().getValue();
-                       },
-
-                       /**
-                        * Compatibility with the $.textSelection jQuery 
plug-in. When the iframe is in use, these functions provide
-                        * equivilant functionality to the otherwise 
textarea-based functionality.
-                        */
-
-                       'getElementAtCursor': function () {
-                               mw.log( 'codeEditor stub function 
getElementAtCursor called' );
                        },
 
                        /**
@@ -567,7 +567,7 @@
                                // Does not yet handle 'ownline', 'splitlines' 
option
                                sel = context.codeEditor.getSelection();
                                range = sel.getRange();
-                               selText = context.fn.getSelection();
+                               selText = textSelectionFn.getSelection();
                                isSample = false;
 
                                if ( !selText ) {
@@ -638,6 +638,7 @@
                                sel.setSelectionRange( range );
                                return context.$textarea;
                        },
+
                        /**
                         * Scroll a textarea to the current cursor position. 
You can set the cursor position with setSelection()
                         * DO NOT CALL THIS DIRECTLY, use $.textSelection( 
'functionname', options ) instead
@@ -645,18 +646,8 @@
                        'scrollToCaretPosition': function ( ) {
                                mw.log( 'codeEditor stub function 
scrollToCaretPosition called' );
                                return context.$textarea;
-                       },
-                       /**
-                        * Scroll an element to the top of the iframe
-                        * DO NOT CALL THIS DIRECTLY, use $.textSelection( 
'functionname', options ) instead
-                        *
-                        * @param $element jQuery object containing an element 
in the iframe
-                        * @param force If true, scroll the element even if 
it's already visible
-                        */
-                       'scrollToTop': function () {
-                               mw.log( 'codeEditor stub function scrollToTop 
called' );
                        }
-               } );
+               };
 
                /* Setup the editor */
                context.fn.setupCodeEditorToolbar();

-- 
To view, visit https://gerrit.wikimedia.org/r/150037
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I57bc7791dc61b7edcf258e6c16445d5a4a8783cf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CodeEditor
Gerrit-Branch: master
Gerrit-Owner: TheDJ <hartman.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to