r82890 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82889‎ | r82890 | r82891 >
Date:13:41, 27 February 2011
Author:junaidpv
Status:ok
Tags:
Comment:
Fix issue found myself on testing: text overwrite was not possible.
Modified paths:
  • /trunk/extensions/Narayam/ext.narayam.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Narayam/ext.narayam.core.js
@@ -155,11 +155,17 @@
156156
157157 var $this = $( this );
158158 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];
160166 // Get the last few characters before the one the user just typed,
161167 // to provide context for the transliteration regexes.
162168 // 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;
164170 var lookback = $this.data( 'narayam-lookback' );
165171 var replacement = transliterate( input, lookback, e.altKey );
166172
@@ -183,8 +189,8 @@
184190
185191 // Select and replace the text
186192 $this.textSelection( 'setSelection', {
187 - 'start': pos - input.length + 1,
188 - 'end': pos
 193+ 'start': startPos - input.length + 1,
 194+ 'end': endPos
189195 } );
190196 $this.textSelection( 'encapsulateSelection', {
191197 'peri': replacement,

Follow-up revisions

RevisionCommit summaryAuthorDate
r82947Narayam: Followup r82890: fix whitespace, rephrase commentcatrope18:42, 28 February 2011

Status & tagging log