Index: trunk/extensions/Narayam/ext.narayam.core.js |
— | — | @@ -155,11 +155,17 @@ |
156 | 156 | |
157 | 157 | var $this = $( this ); |
158 | 158 | var c = String.fromCharCode( e.which ); |
159 | | - var pos = $this.textSelection( 'getCaretPosition' ); |
| 159 | + // Get current caret position |
| 160 | + // User may select text to overwrite |
| 161 | + // Get start and end position of selection |
| 162 | + // In case if user do no selection, both startPos and endPos will be same |
| 163 | + var pos = $this.textSelection( 'getCaretPosition', { 'startAndEnd': true } ); |
| 164 | + var startPos = pos[0]; |
| 165 | + var endPos = pos[1]; |
160 | 166 | // Get the last few characters before the one the user just typed, |
161 | 167 | // to provide context for the transliteration regexes. |
162 | 168 | // We need to append c because it hasn't been added to $this.val() yet |
163 | | - var input = lastNChars( $this.val(), pos, currentScheme.lookbackLength ) + c; |
| 169 | + var input = lastNChars( $this.val(), startPos, currentScheme.lookbackLength ) + c; |
164 | 170 | var lookback = $this.data( 'narayam-lookback' ); |
165 | 171 | var replacement = transliterate( input, lookback, e.altKey ); |
166 | 172 | |
— | — | @@ -183,8 +189,8 @@ |
184 | 190 | |
185 | 191 | // Select and replace the text |
186 | 192 | $this.textSelection( 'setSelection', { |
187 | | - 'start': pos - input.length + 1, |
188 | | - 'end': pos |
| 193 | + 'start': startPos - input.length + 1, |
| 194 | + 'end': endPos |
189 | 195 | } ); |
190 | 196 | $this.textSelection( 'encapsulateSelection', { |
191 | 197 | 'peri': replacement, |