r82945 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r82944‎ | r82945 | r82946 >
Date:18:36, 28 February 2011
Author:catrope
Status:deferred
Tags:
Comment:
Narayam: Fix a bug in r82793 caused by conflation of two similar principles into the term 'lookback'. This commit separates the 'key buffer', which holds the last N keys the user pressed, and the 'lookback length', the number of previous input characters the transliteration regexes need to match against. I will add proper documentation for these concepts in a few days.
Modified paths:
  • /trunk/extensions/Narayam/ext.narayam.core.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.bn-avro.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.bn-inscript.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.bn-nkb.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.hi-inscript.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.kn-inscript.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.kn.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.ml-inscript.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.ml.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.sa-inscript.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.sa.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.ta.js (modified) (history)
  • /trunk/extensions/Narayam/ext.narayam.rules.ta99.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Narayam/ext.narayam.rules.ta99.js
@@ -186,5 +186,6 @@
187187 'namemsg': 'narayam-ta99',
188188 'extended_keyboard': false,
189189 'lookbackLength': 1,
 190+ 'keyBufferLength': 1,
190191 'rules': rules
191192 } );
Index: trunk/extensions/Narayam/ext.narayam.rules.bn-inscript.js
@@ -121,6 +121,7 @@
122122 'namemsg': 'narayam-bn-inscript',
123123 'extended_keyboard': true,
124124 'lookbackLength': 0,
 125+ 'keyBufferLength': 0,
125126 'rules': rules,
126127 'rules_x': rules_x
127128 } );
Index: trunk/extensions/Narayam/ext.narayam.rules.hi-inscript.js
@@ -118,6 +118,7 @@
119119 'namemsg': 'narayam-hi-inscript',
120120 'extended_keyboard': true,
121121 'lookbackLength': 0,
 122+ 'keyBufferLength': 0,
122123 'rules': rules,
123124 'rules_x': rules_x
124125 } );
\ No newline at end of file
Index: trunk/extensions/Narayam/ext.narayam.rules.sa-inscript.js
@@ -110,6 +110,7 @@
111111 'namemsg': 'narayam-sa-inscript',
112112 'extended_keyboard': true,
113113 'lookbackLength': 0,
 114+ 'keyBufferLength': 0,
114115 'rules': rules,
115116 'rules_x': rules_x
116117 } );
\ No newline at end of file
Index: trunk/extensions/Narayam/ext.narayam.core.js
@@ -42,21 +42,21 @@
4343 /**
4444 * Transliterate a string using the current scheme
4545 * @param str String to transliterate
46 - * @param lookback The lookback buffer
 46+ * @param keyBuffer The key buffer
4747 * @param useExtended Whether to use the extended part of the scheme
4848 * @return Transliterated string, or str if no applicable transliteration found.
4949 */
50 - function transliterate( str, lookback, useExtended ) {
 50+ function transliterate( str, keyBuffer, useExtended ) {
5151 var rules = currentScheme.extended_keyboard && useExtended ?
5252 currentScheme.rules_x : currentScheme.rules;
5353 for ( var i = 0; i < rules.length; i++ ) {
54 - var lookbackMatch = true;
55 - if ( rules[i][1].length > 0 && rules[i][1].length <= lookback.length ) {
56 - // Try to match rules[i][1] at the end of the lookback buffer
57 - lookbackMatch = new RegExp( rules[i][1] + '$' ).test( lookback );
 54+ var keyBufferMatch = true;
 55+ if ( rules[i][1].length > 0 && rules[i][1].length <= keyBuffer.length ) {
 56+ // Try to match rules[i][1] at the end of the key buffer
 57+ keyBufferMatch = new RegExp( rules[i][1] + '$' ).test( keyBuffer );
5858 }
5959 var regex = new RegExp( rules[i][0] + '$' );
60 - if ( lookbackMatch && regex.test( str ) ) {
 60+ if ( keyBufferMatch && regex.test( str ) ) {
6161 return str.replace( regex, rules[i][2] );
6262 }
6363 }
@@ -142,8 +142,8 @@
143143 }
144144
145145 if ( e.which == 8 ) { // Backspace
146 - // Blank the lookback buffer
147 - $( this ).data( 'narayam-lookback', '' );
 146+ // Blank the keybuffer
 147+ $( this ).data( 'narayam-keyBuffer', '' );
148148 return true;
149149 }
150150
@@ -166,16 +166,16 @@
167167 // to provide context for the transliteration regexes.
168168 // We need to append c because it hasn't been added to $this.val() yet
169169 var input = lastNChars( $this.val(), startPos, currentScheme.lookbackLength ) + c;
170 - var lookback = $this.data( 'narayam-lookback' );
171 - var replacement = transliterate( input, lookback, e.altKey );
 170+ var keyBuffer = $this.data( 'narayam-keyBuffer' );
 171+ var replacement = transliterate( input, keyBuffer, e.altKey );
172172
173 - // Update the lookback buffer
174 - lookback += c;
175 - if ( lookback.length > currentScheme.lookbackLength ) {
 173+ // Update the key buffer
 174+ keyBuffer += c;
 175+ if ( keyBuffer.length > currentScheme.keyBufferLength ) {
176176 // The buffer is longer than needed, truncate it at the front
177 - lookback = lookback.substring( lookback.length - currentScheme.lookbackLength );
 177+ keyBuffer = keyBuffer.substring( keyBuffer.length - currentScheme.keyBufferLength );
178178 }
179 - $this.data( 'narayam-lookback', lookback );
 179+ $this.data( 'narayam-keyBuffer', keyBuffer );
180180
181181 // textSelection() magic is expensive, so we avoid it as much as we can
182182 if ( replacement == input ) {
@@ -221,7 +221,7 @@
222222 $newInputs
223223 .bind( 'keydown.narayam', onkeydown )
224224 .bind( 'keypress.narayam', onkeypress )
225 - .data( 'narayam-lookback', '' );
 225+ .data( 'narayam-keyBuffer', '' );
226226 if ( enabled ) {
227227 $newInputs.addClass( 'narayam-input' );
228228 }
Index: trunk/extensions/Narayam/ext.narayam.rules.kn-inscript.js
@@ -110,6 +110,7 @@
111111 'namemsg': 'narayam-kn-inscript',
112112 'extended_keyboard': true,
113113 'lookbackLength': 0,
 114+ 'keyBufferLength': 0,
114115 'rules': rules,
115116 'rules_x': rules_x
116117 } );
\ No newline at end of file
Index: trunk/extensions/Narayam/ext.narayam.rules.ml-inscript.js
@@ -78,5 +78,6 @@
7979 'namemsg': 'narayam-ml-inscript',
8080 'extended_keyboard': false,
8181 'lookbackLength': 0,
 82+ 'keyBufferLength': 0,
8283 'rules': rules
8384 } );
Index: trunk/extensions/Narayam/ext.narayam.rules.sa.js
@@ -158,6 +158,7 @@
159159 jQuery.narayam.addScheme( 'sa', {
160160 'namemsg': 'narayam-sa',
161161 'extended_keyboard': false,
162 - 'lookbackLength': 2,
 162+ 'lookbackLength': 4,
 163+ 'keyBufferLength': 1,
163164 'rules': rules
164165 } );
Index: trunk/extensions/Narayam/ext.narayam.rules.ta.js
@@ -105,6 +105,7 @@
106106 jQuery.narayam.addScheme( 'ta', {
107107 'namemsg': 'narayam-ta',
108108 'extended_keyboard': false,
109 - 'lookbackLength': 1,
 109+ 'lookbackLength': 4,
 110+ 'keyBufferLength': 1,
110111 'rules': rules
111112 } );
Index: trunk/extensions/Narayam/ext.narayam.rules.bn-avro.js
@@ -191,6 +191,7 @@
192192 jQuery.narayam.addScheme( 'bn-avro', {
193193 'namemsg': 'narayam-bn-avro',
194194 'extended_keyboard': false,
195 - 'lookbackLength': 5,
 195+ 'lookbackLength': 3,
 196+ 'keyBufferLength': 5,
196197 'rules': rules
197198 } );
Index: trunk/extensions/Narayam/ext.narayam.rules.bn-nkb.js
@@ -132,6 +132,7 @@
133133 'namemsg': 'narayam-bn-nkb',
134134 'extended_keyboard': true,
135135 'lookbackLength': 0,
 136+ 'keyBufferLength': 0,
136137 'rules': rules,
137138 'rules_x': rules_x
138139 } );
Index: trunk/extensions/Narayam/ext.narayam.rules.kn.js
@@ -144,5 +144,6 @@
145145 'namemsg': 'narayam-kn',
146146 'extended_keyboard': false,
147147 'lookbackLength': 3,
 148+ 'keyBufferLength': 1,
148149 'rules': rules
149150 } );
\ No newline at end of file
Index: trunk/extensions/Narayam/ext.narayam.rules.ml.js
@@ -330,6 +330,7 @@
331331 jQuery.narayam.addScheme( 'ml', {
332332 'namemsg': 'narayam-ml',
333333 'extended_keyboard': false,
334 - 'lookbackLength': 4,
 334+ 'lookbackLength': 6,
 335+ 'keyBufferLength': 2,
335336 'rules': rules
336337 } );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r82793Narayam: Rewrote most of the extension. Most important points:...catrope14:56, 25 February 2011

Status & tagging log