Index: branches/wmf/1.18wmf1/resources/jquery/jquery.textSelection.js |
— | — | @@ -101,13 +101,26 @@ |
102 | 102 | } else if ( this.selectionStart || this.selectionStart == '0' ) { |
103 | 103 | // Mozilla/Opera |
104 | 104 | $(this).focus(); |
| 105 | + if ( options.selectionStart !== undefined ) { |
| 106 | + $(this).textSelection( 'setSelection', { 'start': options.selectionStart, 'end': options.selectionEnd } ); |
| 107 | + } |
| 108 | + |
105 | 109 | var selText = $(this).textSelection( 'getSelection' ); |
106 | 110 | var startPos = this.selectionStart; |
107 | 111 | var endPos = this.selectionEnd; |
108 | 112 | var scrollTop = this.scrollTop; |
109 | 113 | checkSelectedText(); |
110 | 114 | |
111 | | - var insertText = pre + selText + post; |
| 115 | + if ( options.selectionStart !== undefined |
| 116 | + && endPos - startPos != options.selectionEnd - options.selectionStart ) |
| 117 | + { |
| 118 | + // This means there is a difference in the selection range returned by browser and what we passed. |
| 119 | + // This happens for Chrome in the case of composite characters. Ref bug #30130 |
| 120 | + // Set the startPos to the correct position. |
| 121 | + startPos = options.selectionStart; |
| 122 | + } |
| 123 | + |
| 124 | + var insertText = pre + selText + post; |
112 | 125 | if ( options.splitlines ) { |
113 | 126 | insertText = doSplitLines( selText, pre, post ); |
114 | 127 | } |
— | — | @@ -141,6 +154,10 @@ |
142 | 155 | if ( context ) { |
143 | 156 | context.fn.restoreCursorAndScrollTop(); |
144 | 157 | } |
| 158 | + if ( options.selectionStart !== undefined ) { |
| 159 | + $(this).textSelection( 'setSelection', { 'start': options.selectionStart, 'end': options.selectionEnd } ); |
| 160 | + } |
| 161 | + |
145 | 162 | var selText = $(this).textSelection( 'getSelection' ); |
146 | 163 | var scrollTop = this.scrollTop; |
147 | 164 | var range = document.selection.createRange(); |
— | — | @@ -413,7 +430,9 @@ |
414 | 431 | 'ownline': false, // Put the inserted text on a line of its own |
415 | 432 | 'replace': false, // If there is a selection, replace it with peri instead of leaving it alone |
416 | 433 | 'selectPeri': true, // Select the peri text if it was inserted (but not if there was a selection and replace==false, or if splitlines==true) |
417 | | - 'splitlines': false // If multiple lines are selected, encapsulate each line individually |
| 434 | + 'splitlines': false, // If multiple lines are selected, encapsulate each line individually |
| 435 | + 'selectionStart': undefined, // Position to start selection at |
| 436 | + 'selectionEnd': undefined // Position to end selection at. Defaults to start |
418 | 437 | }, options ); |
419 | 438 | break; |
420 | 439 | case 'getCaretPosition': |