insertText = doSplitLines( selText, pre, post );
}
if ( options.ownline ) {
- if ( startPos != 0 && this.value.charAt( startPos - 1 ) != "\n" ) {
+ if ( startPos != 0 && this.value.charAt( startPos - 1 ) != "\n" && this.value.charAt( startPos - 1 ) != "\r" ) {
insertText = "\n" + insertText;
+ pre += "\n";
}
- if ( this.value.charAt( endPos ) != "\n" ) {
+ if ( this.value.charAt( endPos ) != "\n" && this.value.charAt( endPos ) != "\r" ) {
insertText += "\n";
+ post += "\n";
}
}
this.value = this.value.substring( 0, startPos ) + insertText +
// FIXME: Which check is correct?
if ( range2.text != "\r" && range2.text != "\n" && range2.text != "" ) {
insertText = "\n" + insertText;
+ pre += "\n";
}
var range3 = document.selection.createRange();
range3.collapse( false );
var length = this.value.length;
// IE doesn't count \n when computing the offset, so we won't either
var newLines = this.value.match( /\n/g );
- if ( newLines) length = length - newLines.length;
+ if ( newLines ) length = length - newLines.length;
selection.moveStart( 'character', options.start );
selection.moveEnd( 'character', -length + options.end );
//$textarea.textSelection( 'setContents', opt.before.text); // this method is actually missing atm...
$textarea.val( opt.before.text ); // won't work with the WikiEditor iframe?
+ var start = opt.before.start,
+ end = opt.before.end;
+ if ( window.opera ) {
+ // Compensate for Opera's craziness converting "\n" to "\r\n" and counting that as two chars
+ var newLinesBefore = opt.before.text.substring( 0, start ).split( "\n" ).length - 1,
+ newLinesInside = opt.before.text.substring( start, end ).split( "\n" ).length - 1;
+ start += newLinesBefore;
+ end += newLinesBefore + newLinesInside;
+ }
$textarea.textSelection( 'setSelection', {
- start: opt.before.start,
- end: opt.before.end
+ start: start,
+ end: end
});
$textarea.textSelection( 'encapsulateSelection', opt.replace );
- var text = $textarea.textSelection( 'getContents' );
+ var text = $textarea.textSelection( 'getContents' ).replace( /\r\n/g, "\n" );
equal( text, opt.after.text, 'Checking full text after encapsulation' );