Index: trunk/extensions/CodeEditor/modules/jquery.codeEditor.js |
— | — | @@ -114,7 +114,7 @@ |
115 | 115 | } |
116 | 116 | ]; |
117 | 117 | box.closest('form').submit(function(event) { |
118 | | - box.val(context.codeEditor.getSession().getValue()); |
| 118 | + box.val(context.fn.getContents()); |
119 | 119 | }); |
120 | 120 | context.codeEditor.getSession().setMode(new (require("ace/mode/" + lang).Mode)); |
121 | 121 | |
— | — | @@ -141,6 +141,11 @@ |
142 | 142 | } |
143 | 143 | }, |
144 | 144 | |
| 145 | + /* Needed for search/replace */ |
| 146 | + 'getContents': function() { |
| 147 | + return context.codeEditor.getSession().getValue(); |
| 148 | + }, |
| 149 | + |
145 | 150 | /* |
146 | 151 | * Compatibility with the $.textSelection jQuery plug-in. When the iframe is in use, these functions provide |
147 | 152 | * equivilant functionality to the otherwise textarea-based functionality. |
— | — | @@ -183,6 +188,7 @@ |
184 | 189 | range.setEnd( range.start.row, range.start.column + selText.length ); |
185 | 190 | sel.setSelectionRange(range); |
186 | 191 | } |
| 192 | + return context.$textarea; |
187 | 193 | }, |
188 | 194 | /** |
189 | 195 | * Gets the position (in resolution of bytes not nessecarily characters) in a textarea |
— | — | @@ -200,6 +206,31 @@ |
201 | 207 | * @param endContainer Element in iframe to end selection in. If not set, end is a character offset |
202 | 208 | */ |
203 | 209 | 'setSelection': function( options ) { |
| 210 | + // Ace stores positions for ranges as row/column pairs. |
| 211 | + // To convert from character offsets, we'll need to iterate through the document |
| 212 | + var doc = context.codeEditor.getSession().getDocument(); |
| 213 | + var lines = doc.getAllLines(); |
| 214 | + |
| 215 | + var offsetToPos = function( offset ) { |
| 216 | + var row = 0, col = 0; |
| 217 | + var pos = 0; |
| 218 | + while ( row < lines.length && pos + lines[row].length < offset) { |
| 219 | + pos += lines[row].length; |
| 220 | + pos++; // for the newline |
| 221 | + row++; |
| 222 | + } |
| 223 | + col = offset - pos; |
| 224 | + return {row: row, column: col}; |
| 225 | + } |
| 226 | + var start = offsetToPos( options.start ), |
| 227 | + end = offsetToPos( options.end ); |
| 228 | + |
| 229 | + var sel = context.codeEditor.getSelection(); |
| 230 | + var range = sel.getRange(); |
| 231 | + range.setStart( start.row, start.column ); |
| 232 | + range.setEnd( end.row, end.column ); |
| 233 | + sel.setSelectionRange( range ); |
| 234 | + return context.$textarea; |
204 | 235 | }, |
205 | 236 | /** |
206 | 237 | * Scroll a textarea to the current cursor position. You can set the cursor position with setSelection() |
— | — | @@ -207,6 +238,7 @@ |
208 | 239 | */ |
209 | 240 | 'scrollToCaretPosition': function( options ) { |
210 | 241 | //context.fn.scrollToTop( context.fn.getElementAtCursor(), true ); |
| 242 | + return context.$textarea; |
211 | 243 | }, |
212 | 244 | /** |
213 | 245 | * Scroll an element to the top of the iframe |