http://www.mediawiki.org/wiki/Special:Code/MediaWiki/82945

Revision: 82945
Author:   catrope
Date:     2011-02-28 18:36:38 +0000 (Mon, 28 Feb 2011)
Log Message:
-----------
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
    trunk/extensions/Narayam/ext.narayam.rules.bn-avro.js
    trunk/extensions/Narayam/ext.narayam.rules.bn-inscript.js
    trunk/extensions/Narayam/ext.narayam.rules.bn-nkb.js
    trunk/extensions/Narayam/ext.narayam.rules.hi-inscript.js
    trunk/extensions/Narayam/ext.narayam.rules.kn-inscript.js
    trunk/extensions/Narayam/ext.narayam.rules.kn.js
    trunk/extensions/Narayam/ext.narayam.rules.ml-inscript.js
    trunk/extensions/Narayam/ext.narayam.rules.ml.js
    trunk/extensions/Narayam/ext.narayam.rules.sa-inscript.js
    trunk/extensions/Narayam/ext.narayam.rules.sa.js
    trunk/extensions/Narayam/ext.narayam.rules.ta.js
    trunk/extensions/Narayam/ext.narayam.rules.ta99.js

Modified: trunk/extensions/Narayam/ext.narayam.core.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.core.js        2011-02-28 18:34:04 UTC 
(rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.core.js        2011-02-28 18:36:38 UTC 
(rev 82945)
@@ -42,21 +42,21 @@
        /**
         * Transliterate a string using the current scheme
         * @param str String to transliterate
-        * @param lookback The lookback buffer
+        * @param keyBuffer The key buffer
         * @param useExtended Whether to use the extended part of the scheme
         * @return Transliterated string, or str if no applicable 
transliteration found.
         */
-       function transliterate( str, lookback, useExtended ) {
+       function transliterate( str, keyBuffer, useExtended ) {
                var rules = currentScheme.extended_keyboard && useExtended ?
                        currentScheme.rules_x : currentScheme.rules;
                for ( var i = 0;  i < rules.length; i++ ) {
-                       var lookbackMatch = true;
-                       if ( rules[i][1].length > 0 && rules[i][1].length <= 
lookback.length ) {
-                               // Try to match rules[i][1] at the end of the 
lookback buffer
-                               lookbackMatch = new RegExp( rules[i][1] + '$' 
).test( lookback );
+                       var keyBufferMatch = true;
+                       if ( rules[i][1].length > 0 && rules[i][1].length <= 
keyBuffer.length ) {
+                               // Try to match rules[i][1] at the end of the 
key buffer
+                               keyBufferMatch = new RegExp( rules[i][1] + '$' 
).test( keyBuffer );
                        }
                        var regex = new RegExp( rules[i][0] + '$' );
-                       if ( lookbackMatch && regex.test( str ) ) {
+                       if ( keyBufferMatch && regex.test( str ) ) {
                                return str.replace( regex, rules[i][2] );
                        }
                }
@@ -142,8 +142,8 @@
                }
                
                if ( e.which == 8 ) { // Backspace
-                       // Blank the lookback buffer
-                       $( this ).data( 'narayam-lookback', '' );
+                       // Blank the keybuffer
+                       $( this ).data( 'narayam-keyBuffer', '' );
                        return true;
                }
                
@@ -166,16 +166,16 @@
                // to provide context for the transliteration regexes.
                // We need to append c because it hasn't been added to 
$this.val() yet
                var input = lastNChars( $this.val(), startPos, 
currentScheme.lookbackLength ) + c;
-               var lookback = $this.data( 'narayam-lookback' );
-               var replacement = transliterate( input, lookback, e.altKey );
+               var keyBuffer = $this.data( 'narayam-keyBuffer' );
+               var replacement = transliterate( input, keyBuffer, e.altKey );
                
-               // Update the lookback buffer
-               lookback += c;
-               if ( lookback.length > currentScheme.lookbackLength ) {
+               // Update the key buffer
+               keyBuffer += c;
+               if ( keyBuffer.length > currentScheme.keyBufferLength ) {
                        // The buffer is longer than needed, truncate it at the 
front
-                       lookback = lookback.substring( lookback.length - 
currentScheme.lookbackLength );
+                       keyBuffer = keyBuffer.substring( keyBuffer.length - 
currentScheme.keyBufferLength );
                }
-               $this.data( 'narayam-lookback', lookback );
+               $this.data( 'narayam-keyBuffer', keyBuffer );
                
                // textSelection() magic is expensive, so we avoid it as much 
as we can
                if ( replacement == input ) {
@@ -221,7 +221,7 @@
                $newInputs
                        .bind( 'keydown.narayam', onkeydown )
                        .bind( 'keypress.narayam', onkeypress )
-                       .data( 'narayam-lookback', '' );
+                       .data( 'narayam-keyBuffer', '' );
                if ( enabled ) {
                        $newInputs.addClass( 'narayam-input' );
                }

Modified: trunk/extensions/Narayam/ext.narayam.rules.bn-avro.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.bn-avro.js       2011-02-28 
18:34:04 UTC (rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.bn-avro.js       2011-02-28 
18:36:38 UTC (rev 82945)
@@ -191,6 +191,7 @@
 jQuery.narayam.addScheme( 'bn-avro', {
        'namemsg': 'narayam-bn-avro',
        'extended_keyboard': false,
-       'lookbackLength': 5,
+       'lookbackLength': 3,
+       'keyBufferLength': 5,
        'rules': rules
 } );

Modified: trunk/extensions/Narayam/ext.narayam.rules.bn-inscript.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.bn-inscript.js   2011-02-28 
18:34:04 UTC (rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.bn-inscript.js   2011-02-28 
18:36:38 UTC (rev 82945)
@@ -121,6 +121,7 @@
        'namemsg': 'narayam-bn-inscript',
        'extended_keyboard': true,
        'lookbackLength': 0,
+       'keyBufferLength': 0,
        'rules': rules,
        'rules_x': rules_x
 } );

Modified: trunk/extensions/Narayam/ext.narayam.rules.bn-nkb.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.bn-nkb.js        2011-02-28 
18:34:04 UTC (rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.bn-nkb.js        2011-02-28 
18:36:38 UTC (rev 82945)
@@ -132,6 +132,7 @@
        'namemsg': 'narayam-bn-nkb',
        'extended_keyboard': true,
        'lookbackLength': 0,
+       'keyBufferLength': 0,
        'rules': rules,
        'rules_x': rules_x
 } );

Modified: trunk/extensions/Narayam/ext.narayam.rules.hi-inscript.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.hi-inscript.js   2011-02-28 
18:34:04 UTC (rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.hi-inscript.js   2011-02-28 
18:36:38 UTC (rev 82945)
@@ -118,6 +118,7 @@
     'namemsg': 'narayam-hi-inscript',
     'extended_keyboard': true,
     'lookbackLength': 0,
+    'keyBufferLength': 0,
     'rules': rules,
     'rules_x': rules_x
 } ); 
\ No newline at end of file

Modified: trunk/extensions/Narayam/ext.narayam.rules.kn-inscript.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.kn-inscript.js   2011-02-28 
18:34:04 UTC (rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.kn-inscript.js   2011-02-28 
18:36:38 UTC (rev 82945)
@@ -110,6 +110,7 @@
     'namemsg': 'narayam-kn-inscript',
     'extended_keyboard': true,
     'lookbackLength': 0,
+    'keyBufferLength': 0,
     'rules': rules,
     'rules_x': rules_x
 } ); 
\ No newline at end of file

Modified: trunk/extensions/Narayam/ext.narayam.rules.kn.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.kn.js    2011-02-28 18:34:04 UTC 
(rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.kn.js    2011-02-28 18:36:38 UTC 
(rev 82945)
@@ -144,5 +144,6 @@
     'namemsg': 'narayam-kn',
     'extended_keyboard': false,
     'lookbackLength': 3,
+    'keyBufferLength': 1,
     'rules': rules
 } ); 
\ No newline at end of file

Modified: trunk/extensions/Narayam/ext.narayam.rules.ml-inscript.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.ml-inscript.js   2011-02-28 
18:34:04 UTC (rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.ml-inscript.js   2011-02-28 
18:36:38 UTC (rev 82945)
@@ -78,5 +78,6 @@
        'namemsg': 'narayam-ml-inscript',
        'extended_keyboard': false,
        'lookbackLength': 0,
+       'keyBufferLength': 0,
        'rules': rules
 } );

Modified: trunk/extensions/Narayam/ext.narayam.rules.ml.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.ml.js    2011-02-28 18:34:04 UTC 
(rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.ml.js    2011-02-28 18:36:38 UTC 
(rev 82945)
@@ -330,6 +330,7 @@
 jQuery.narayam.addScheme( 'ml', {
        'namemsg': 'narayam-ml',
        'extended_keyboard': false,
-       'lookbackLength': 4,
+       'lookbackLength': 6,
+       'keyBufferLength': 2,
        'rules': rules
 } );

Modified: trunk/extensions/Narayam/ext.narayam.rules.sa-inscript.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.sa-inscript.js   2011-02-28 
18:34:04 UTC (rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.sa-inscript.js   2011-02-28 
18:36:38 UTC (rev 82945)
@@ -110,6 +110,7 @@
        'namemsg': 'narayam-sa-inscript',
        'extended_keyboard': true,
        'lookbackLength': 0,
+       'keyBufferLength': 0,
        'rules': rules,
        'rules_x': rules_x
 } );
\ No newline at end of file

Modified: trunk/extensions/Narayam/ext.narayam.rules.sa.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.sa.js    2011-02-28 18:34:04 UTC 
(rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.sa.js    2011-02-28 18:36:38 UTC 
(rev 82945)
@@ -158,6 +158,7 @@
 jQuery.narayam.addScheme( 'sa', {
        'namemsg': 'narayam-sa',
        'extended_keyboard': false,
-       'lookbackLength': 2,
+       'lookbackLength': 4,
+       'keyBufferLength': 1,
        'rules': rules
 } );

Modified: trunk/extensions/Narayam/ext.narayam.rules.ta.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.ta.js    2011-02-28 18:34:04 UTC 
(rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.ta.js    2011-02-28 18:36:38 UTC 
(rev 82945)
@@ -105,6 +105,7 @@
 jQuery.narayam.addScheme( 'ta', {
        'namemsg': 'narayam-ta',
        'extended_keyboard': false,
-       'lookbackLength': 1,
+       'lookbackLength': 4,
+       'keyBufferLength': 1,
        'rules': rules
 } );

Modified: trunk/extensions/Narayam/ext.narayam.rules.ta99.js
===================================================================
--- trunk/extensions/Narayam/ext.narayam.rules.ta99.js  2011-02-28 18:34:04 UTC 
(rev 82944)
+++ trunk/extensions/Narayam/ext.narayam.rules.ta99.js  2011-02-28 18:36:38 UTC 
(rev 82945)
@@ -186,5 +186,6 @@
        'namemsg': 'narayam-ta99',
        'extended_keyboard': false,
        'lookbackLength': 1,
+       'keyBufferLength': 1,
        'rules': rules
 } );


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to