http://www.mediawiki.org/wiki/Special:Code/MediaWiki/89844

Revision: 89844
Author:   brion
Date:     2011-06-10 19:32:53 +0000 (Fri, 10 Jun 2011)
Log Message:
-----------
CodeEditor: fix for encapsulateSelection; now handles replacements & selection 
for standard cases (bold/italic/link insertion, quote pairs, etc)

Modified Paths:
--------------
    trunk/extensions/CodeEditor/modules/jquery.codeEditor.js

Modified: trunk/extensions/CodeEditor/modules/jquery.codeEditor.js
===================================================================
--- trunk/extensions/CodeEditor/modules/jquery.codeEditor.js    2011-06-10 
19:11:53 UTC (rev 89843)
+++ trunk/extensions/CodeEditor/modules/jquery.codeEditor.js    2011-06-10 
19:32:53 UTC (rev 89844)
@@ -154,7 +154,7 @@
         * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', 
options ) instead
         */
        'getSelection': function() {
-               return context.$codeEditor.getSelectionRange();
+               return context.codeEditor.getCopyText();
        },
        /**
         * Inserts text at the begining and end of a text selection, optionally 
inserting text at the caret when
@@ -162,9 +162,27 @@
         * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', 
options ) instead
         */
        'encapsulateSelection': function( options ) {
-               // Hack! Handle actual selection logic.
-               var text = options.pre + options.peri + options.post;
+               // Does not yet handle 'ownline', 'splitlines' option
+               var sel = context.codeEditor.getSelection();
+               var range = sel.getRange();
+               var selText = context.fn.getSelection();
+               var selectAfter = false;
+               if ( !selText ) {
+                       selText = options.peri;
+                       selectAfter = true;
+               } else if ( options.replace ) {
+                       selText = options.peri;
+               }
+               var text = options.pre;
+               text += selText;
+               text += options.post;
                context.codeEditor.insert( text );
+               if ( selectAfter ) {
+                       // May esplode if anything has newlines, be warned. :)
+                       range.setStart( range.start.row, range.start.column + 
options.pre.length );
+                       range.setEnd( range.start.row, range.start.column + 
selText.length );
+                       sel.setSelectionRange(range);
+               }
        },
        /**
         * Gets the position (in resolution of bytes not nessecarily 
characters) in a textarea


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to