r89844 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89843‎ | r89844 | r89845 >
Date:19:32, 10 June 2011
Author:brion
Status:deferred
Tags:
Comment:
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) (history)

Diff [purge]

Index: trunk/extensions/CodeEditor/modules/jquery.codeEditor.js
@@ -154,7 +154,7 @@
155155 * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead
156156 */
157157 'getSelection': function() {
158 - return context.$codeEditor.getSelectionRange();
 158+ return context.codeEditor.getCopyText();
159159 },
160160 /**
161161 * Inserts text at the begining and end of a text selection, optionally inserting text at the caret when
@@ -162,9 +162,27 @@
163163 * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead
164164 */
165165 'encapsulateSelection': function( options ) {
166 - // Hack! Handle actual selection logic.
167 - var text = options.pre + options.peri + options.post;
 166+ // Does not yet handle 'ownline', 'splitlines' option
 167+ var sel = context.codeEditor.getSelection();
 168+ var range = sel.getRange();
 169+ var selText = context.fn.getSelection();
 170+ var selectAfter = false;
 171+ if ( !selText ) {
 172+ selText = options.peri;
 173+ selectAfter = true;
 174+ } else if ( options.replace ) {
 175+ selText = options.peri;
 176+ }
 177+ var text = options.pre;
 178+ text += selText;
 179+ text += options.post;
168180 context.codeEditor.insert( text );
 181+ if ( selectAfter ) {
 182+ // May esplode if anything has newlines, be warned. :)
 183+ range.setStart( range.start.row, range.start.column + options.pre.length );
 184+ range.setEnd( range.start.row, range.start.column + selText.length );
 185+ sel.setSelectionRange(range);
 186+ }
169187 },
170188 /**
171189 * Gets the position (in resolution of bytes not nessecarily characters) in a textarea

Status & tagging log