https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112289

Revision: 112289
Author:   inez
Date:     2012-02-24 01:43:33 +0000 (Fri, 24 Feb 2012)
Log Message:
-----------
Testing new approach figure out where the change is coming from based on the 
cursor offset, not based on key events

Modified Paths:
--------------
    trunk/extensions/VisualEditor/demos/playground/playground.js

Modified: trunk/extensions/VisualEditor/demos/playground/playground.js
===================================================================
--- trunk/extensions/VisualEditor/demos/playground/playground.js        
2012-02-24 01:38:53 UTC (rev 112288)
+++ trunk/extensions/VisualEditor/demos/playground/playground.js        
2012-02-24 01:43:33 UTC (rev 112289)
@@ -32,109 +32,123 @@
        this.$editor.html("<b>Lorem Ipsum is simply dummy text</b> of the 
printing and typesetting industry. <b>Lorem Ipsum has been the 
<i>industry's</i> standard</b> dummy text ever since the 1500s, when an unknown 
printer took a galley of type and scrambled it <u>to <b>make <i>a type</i> 
specimen</b> book.</u>");
        this.$editor.addClass('leafNode');
 
+       this.lastKeydown = null;
        this.keydown = false;
        this.keyup = false;
        this.keypress = false;
        this.mousedown = false;
-       this.inime = false;
+       this.diff = false;
        this.prevText = app.getDOMText(this.$editor[0]);
+       this.prevOffset = null;
+       this.loop = false;
        
-       setInterval(function() {
-               _this.loopFunc();
-       }, 100);
+       this.logkey = false;
 };
 
 app.prototype.onKeyDown = function( e ) {
-       console.log("onKeyDown");
+       if(this.logkey) console.log("onKeyDown", e.which);
        this.keydown = true;
-       if ( e.which === 229 ) {
-               this.inime = true;
-       }
+       this.lastKeydown = e.which;
 };
 
 app.prototype.onKeyUp = function( e ) {
-       console.log("onKeyUp");
+       if(this.logkey) console.log("onKeyUp", e.which);
        this.keyup = true;
-       if ( this.inime ) {
-               this.inime = false;
-       }
 };
 
 app.prototype.onKeyPress = function( e ) {
-       //console.log("onKeyPress");
+       if(this.logkey) console.log("onKeyPress");
        this.keypress = true;
-       if ( e.which === 229 ) {
-               this.inime = true;
-       }       
 };
 
 app.prototype.onMouseDown = function( e ) {
+       if(this.logkey) console.log("onMouseDown");
        this.mousedown = true;
 
-       if ( this.inime ) {
-               this.inime = false;
+       if(this.loop == false) {
+               var _this = this;
+               setInterval(function() {
+                       _this.loopFunc();
+               }, 100);                
        }
 };
 
 app.prototype.loopFunc = function() {
-       var text = app.getDOMText(this.$editor[0]);
+       var text = 
app.getDOMText(this.$editor[0]).replace(String.fromCharCode(32), " 
").replace(String.fromCharCode(160), " ");
+       var selection = rangy.getSelection();
+       if ( !selection.anchorNode ) {
+               console.log("och");
+               return;
+       }
+       var offset = this.getOffset(selection.anchorNode, 
selection.anchorOffset);
 
        if(text != this.prevText) {
+               var textDiffLength = text.length - this.prevText.length;
+               var offsetDiff = offset - this.prevOffset;
+               var sameFromLeft = 0;
+               var l = text.length;
+               while ( sameFromLeft < l && this.prevText[sameFromLeft] == 
text[sameFromLeft] ) {
+                       ++sameFromLeft;
+               }
+               
 
-               console.log("text is different");
-               
-               if(this.keydown) {
-                       console.log("keyboard");
-               } else {
-                       console.log("not keyboard");
+               if(false) {
+                       console.log("change start", sameFromLeft, offset);      
        
+                       console.log("different content", textDiffLength);
+                       console.log("different offset", offsetDiff);
                }
 
-               this.prevText = text;
-       }
-       
-       this.keypress = false;
-       this.keyup = false;
-       this.keydown = false;
-       this.mousedown = false;
+               if ( sameFromLeft != offset - textDiffLength ) {
+                       console.log('spell');
+               }
 
-       /*
 
-               var selection = rangy.getSelection();
 
+               
+               /*
+               else if(textDiffLength === -1 && offsetDiff === -1 && offset 
=== sameFromLeft ) {
+                       console.log("IME.1");
+               } else if(textDiffLength === 0 && offsetDiff === 0 && offset-1 
=== sameFromLeft ) {
+                       console.log("IME.2");
+               } else if ( textDiffLength < 0 || ( offset - textDiffLength ) 
!== sameFromLeft ) {
+                       console.log("SPELLCHECK");
+               } else {
+                       console.log("!");
+               }
+               */
+               
+               
+               
+               if ( textDiffLength !== offsetDiff ) {
+                       //console.log("!!!!#####!!!!!");
+               }
 
-
-               // keyup in IE
-               // keypress and keydown in FF and Chrome
-               if ( (($.browser.msie && !this.keyup) || (!$.browser.msie && 
!this.keypress && !this.mousedown)) && !this.inime ) {
-                       console.log(this.inime);
-                       console.log('SPELLCHECK');
-                       this.prevText = text;
-                       this.keypress = false;
-                       this.keyup = false;
-                       this.mousedown = false;
-                       return;
+               if(!this.keydown) {
+                       //console.log("## not keyboard");
+               } else {
+                       //console.log("@@ keyboard");
                }
 
-               console.log("keyboard");
-               // we are going to need a cursor position
-               var offset = this.getOffset( selection.anchorNode, 
selection.anchorOffset );
-               var diffLength = text.length - this.prevText.length;
-               //console.log("diffLength: " + diffLength);
-               
-               if ( diffLength > 0 ) {
-                       //console.log( text.substring(offset - diffLength, 
offset) );   
-               } else if ( diffLength === 0 ) {
-                       //console.log( text.substring(offset - 1, offset) );
+
+
+/*
+               if((this.keydown || this.keyup) && this.lastKeydown !== 229) {
+                       console.log("");
+               } else {
+                       console.log("Do NOT re-render");
                }
-
-               
+*/
                this.prevText = text;
+               this.diff = true;
+       } else {
+               this.diff = false;
        }
+       
+       this.prevOffset = offset;
        this.keypress = false;
        this.keyup = false;
        this.keydown = false;
        this.mousedown = false;
-       */
 };
 
 app.getDOMText = function( elem ) {
@@ -158,7 +172,7 @@
         return elem.nodeValue;
     }
 
-    return ret; 
+    return ret;
 };
 
 app.prototype.getOffset = function( localNode, localOffset ) {


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

Reply via email to