r112289 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112288‎ | r112289 | r112290 >
Date:01:43, 24 February 2012
Author:inez
Status:deferred
Tags:
Comment:
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) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/demos/playground/playground.js
@@ -32,109 +32,123 @@
3333 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>");
3434 this.$editor.addClass('leafNode');
3535
 36+ this.lastKeydown = null;
3637 this.keydown = false;
3738 this.keyup = false;
3839 this.keypress = false;
3940 this.mousedown = false;
40 - this.inime = false;
 41+ this.diff = false;
4142 this.prevText = app.getDOMText(this.$editor[0]);
 43+ this.prevOffset = null;
 44+ this.loop = false;
4245
43 - setInterval(function() {
44 - _this.loopFunc();
45 - }, 100);
 46+ this.logkey = false;
4647 };
4748
4849 app.prototype.onKeyDown = function( e ) {
49 - console.log("onKeyDown");
 50+ if(this.logkey) console.log("onKeyDown", e.which);
5051 this.keydown = true;
51 - if ( e.which === 229 ) {
52 - this.inime = true;
53 - }
 52+ this.lastKeydown = e.which;
5453 };
5554
5655 app.prototype.onKeyUp = function( e ) {
57 - console.log("onKeyUp");
 56+ if(this.logkey) console.log("onKeyUp", e.which);
5857 this.keyup = true;
59 - if ( this.inime ) {
60 - this.inime = false;
61 - }
6258 };
6359
6460 app.prototype.onKeyPress = function( e ) {
65 - //console.log("onKeyPress");
 61+ if(this.logkey) console.log("onKeyPress");
6662 this.keypress = true;
67 - if ( e.which === 229 ) {
68 - this.inime = true;
69 - }
7063 };
7164
7265 app.prototype.onMouseDown = function( e ) {
 66+ if(this.logkey) console.log("onMouseDown");
7367 this.mousedown = true;
7468
75 - if ( this.inime ) {
76 - this.inime = false;
 69+ if(this.loop == false) {
 70+ var _this = this;
 71+ setInterval(function() {
 72+ _this.loopFunc();
 73+ }, 100);
7774 }
7875 };
7976
8077 app.prototype.loopFunc = function() {
81 - var text = app.getDOMText(this.$editor[0]);
 78+ var text = app.getDOMText(this.$editor[0]).replace(String.fromCharCode(32), " ").replace(String.fromCharCode(160), " ");
 79+ var selection = rangy.getSelection();
 80+ if ( !selection.anchorNode ) {
 81+ console.log("och");
 82+ return;
 83+ }
 84+ var offset = this.getOffset(selection.anchorNode, selection.anchorOffset);
8285
8386 if(text != this.prevText) {
 87+ var textDiffLength = text.length - this.prevText.length;
 88+ var offsetDiff = offset - this.prevOffset;
 89+ var sameFromLeft = 0;
 90+ var l = text.length;
 91+ while ( sameFromLeft < l && this.prevText[sameFromLeft] == text[sameFromLeft] ) {
 92+ ++sameFromLeft;
 93+ }
 94+
8495
85 - console.log("text is different");
86 -
87 - if(this.keydown) {
88 - console.log("keyboard");
89 - } else {
90 - console.log("not keyboard");
 96+ if(false) {
 97+ console.log("change start", sameFromLeft, offset);
 98+ console.log("different content", textDiffLength);
 99+ console.log("different offset", offsetDiff);
91100 }
92101
93 - this.prevText = text;
94 - }
95 -
96 - this.keypress = false;
97 - this.keyup = false;
98 - this.keydown = false;
99 - this.mousedown = false;
 102+ if ( sameFromLeft != offset - textDiffLength ) {
 103+ console.log('spell');
 104+ }
100105
101 - /*
102106
103 - var selection = rangy.getSelection();
104107
 108+
 109+ /*
 110+ else if(textDiffLength === -1 && offsetDiff === -1 && offset === sameFromLeft ) {
 111+ console.log("IME.1");
 112+ } else if(textDiffLength === 0 && offsetDiff === 0 && offset-1 === sameFromLeft ) {
 113+ console.log("IME.2");
 114+ } else if ( textDiffLength < 0 || ( offset - textDiffLength ) !== sameFromLeft ) {
 115+ console.log("SPELLCHECK");
 116+ } else {
 117+ console.log("!");
 118+ }
 119+ */
 120+
 121+
 122+
 123+ if ( textDiffLength !== offsetDiff ) {
 124+ //console.log("!!!!#####!!!!!");
 125+ }
105126
106 -
107 - // keyup in IE
108 - // keypress and keydown in FF and Chrome
109 - if ( (($.browser.msie && !this.keyup) || (!$.browser.msie && !this.keypress && !this.mousedown)) && !this.inime ) {
110 - console.log(this.inime);
111 - console.log('SPELLCHECK');
112 - this.prevText = text;
113 - this.keypress = false;
114 - this.keyup = false;
115 - this.mousedown = false;
116 - return;
 127+ if(!this.keydown) {
 128+ //console.log("## not keyboard");
 129+ } else {
 130+ //console.log("@@ keyboard");
117131 }
118132
119 - console.log("keyboard");
120 - // we are going to need a cursor position
121 - var offset = this.getOffset( selection.anchorNode, selection.anchorOffset );
122 - var diffLength = text.length - this.prevText.length;
123 - //console.log("diffLength: " + diffLength);
124 -
125 - if ( diffLength > 0 ) {
126 - //console.log( text.substring(offset - diffLength, offset) );
127 - } else if ( diffLength === 0 ) {
128 - //console.log( text.substring(offset - 1, offset) );
 133+
 134+
 135+/*
 136+ if((this.keydown || this.keyup) && this.lastKeydown !== 229) {
 137+ console.log("");
 138+ } else {
 139+ console.log("Do NOT re-render");
129140 }
130 -
131 -
 141+*/
132142 this.prevText = text;
 143+ this.diff = true;
 144+ } else {
 145+ this.diff = false;
133146 }
 147+
 148+ this.prevOffset = offset;
134149 this.keypress = false;
135150 this.keyup = false;
136151 this.keydown = false;
137152 this.mousedown = false;
138 - */
139153 };
140154
141155 app.getDOMText = function( elem ) {
@@ -158,7 +172,7 @@
159173 return elem.nodeValue;
160174 }
161175
162 - return ret;
 176+ return ret;
163177 };
164178
165179 app.prototype.getOffset = function( localNode, localOffset ) {

Status & tagging log