Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.js |
— | — | @@ -50,14 +50,23 @@ |
51 | 51 | //$textarea.textSelection( 'setContents', opt.before.text); // this method is actually missing atm... |
52 | 52 | $textarea.val( opt.before.text ); // won't work with the WikiEditor iframe? |
53 | 53 | |
| 54 | + var start = opt.before.start, |
| 55 | + end = opt.before.end; |
| 56 | + if ( window.opera ) { |
| 57 | + // Compensate for Opera's craziness converting "\n" to "\r\n" and counting that as two chars |
| 58 | + var newLinesBefore = opt.before.text.substring( 0, start ).split( "\n" ).length - 1, |
| 59 | + newLinesInside = opt.before.text.substring( start, end ).split( "\n" ).length - 1; |
| 60 | + start += newLinesBefore; |
| 61 | + end += newLinesBefore + newLinesInside; |
| 62 | + } |
54 | 63 | $textarea.textSelection( 'setSelection', { |
55 | | - start: opt.before.start, |
56 | | - end: opt.before.end |
| 64 | + start: start, |
| 65 | + end: end |
57 | 66 | }); |
58 | 67 | |
59 | 68 | $textarea.textSelection( 'encapsulateSelection', opt.replace ); |
60 | 69 | |
61 | | - var text = $textarea.textSelection( 'getContents' ); |
| 70 | + var text = $textarea.textSelection( 'getContents' ).replace( /\r\n/g, "\n" ); |
62 | 71 | |
63 | 72 | equal( text, opt.after.text, 'Checking full text after encapsulation' ); |
64 | 73 | |
Index: trunk/phase3/resources/jquery/jquery.textSelection.js |
— | — | @@ -112,11 +112,13 @@ |
113 | 113 | insertText = doSplitLines( selText, pre, post ); |
114 | 114 | } |
115 | 115 | if ( options.ownline ) { |
116 | | - if ( startPos != 0 && this.value.charAt( startPos - 1 ) != "\n" ) { |
| 116 | + if ( startPos != 0 && this.value.charAt( startPos - 1 ) != "\n" && this.value.charAt( startPos - 1 ) != "\r" ) { |
117 | 117 | insertText = "\n" + insertText; |
| 118 | + pre += "\n"; |
118 | 119 | } |
119 | | - if ( this.value.charAt( endPos ) != "\n" ) { |
| 120 | + if ( this.value.charAt( endPos ) != "\n" && this.value.charAt( endPos ) != "\r" ) { |
120 | 121 | insertText += "\n"; |
| 122 | + post += "\n"; |
121 | 123 | } |
122 | 124 | } |
123 | 125 | this.value = this.value.substring( 0, startPos ) + insertText + |
— | — | @@ -157,6 +159,7 @@ |
158 | 160 | // FIXME: Which check is correct? |
159 | 161 | if ( range2.text != "\r" && range2.text != "\n" && range2.text != "" ) { |
160 | 162 | insertText = "\n" + insertText; |
| 163 | + pre += "\n"; |
161 | 164 | } |
162 | 165 | var range3 = document.selection.createRange(); |
163 | 166 | range3.collapse( false ); |
— | — | @@ -292,7 +295,7 @@ |
293 | 296 | var length = this.value.length; |
294 | 297 | // IE doesn't count \n when computing the offset, so we won't either |
295 | 298 | var newLines = this.value.match( /\n/g ); |
296 | | - if ( newLines) length = length - newLines.length; |
| 299 | + if ( newLines ) length = length - newLines.length; |
297 | 300 | selection.moveStart( 'character', options.start ); |
298 | 301 | selection.moveEnd( 'character', -length + options.end ); |
299 | 302 | |