Index: trunk/extensions/CodeEditor/modules/jquery.codeEditor.js |
— | — | @@ -154,7 +154,7 @@ |
155 | 155 | * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead |
156 | 156 | */ |
157 | 157 | 'getSelection': function() { |
158 | | - return context.$codeEditor.getSelectionRange(); |
| 158 | + return context.codeEditor.getCopyText(); |
159 | 159 | }, |
160 | 160 | /** |
161 | 161 | * Inserts text at the begining and end of a text selection, optionally inserting text at the caret when |
— | — | @@ -162,9 +162,27 @@ |
163 | 163 | * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead |
164 | 164 | */ |
165 | 165 | '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; |
168 | 180 | 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 | + } |
169 | 187 | }, |
170 | 188 | /** |
171 | 189 | * Gets the position (in resolution of bytes not nessecarily characters) in a textarea |