r110995 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110994‎ | r110995 | r110996 >
Date:00:51, 9 February 2012
Author:inez
Status:deferred
Tags:
Comment:
First implementation of IME for content editable
Modified paths:
  • /trunk/extensions/VisualEditor/contentEditable/ime.html (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Content.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/contentEditable/ime.html
@@ -53,6 +53,41 @@
5454 }
5555
5656 } );
 57+
 58+ var oldText = 'Test';
 59+ var newText = 'Teeeeeest';
 60+
 61+ var sameFromLeft = 0,
 62+ sameFromRight = 0,
 63+ l = oldText.length;
 64+
 65+ while ( sameFromLeft < l && oldText[sameFromLeft] == newText[sameFromLeft] ) {
 66+ ++sameFromLeft;
 67+ }
 68+ if ( oldText.length > sameFromLeft ) {
 69+ l = l - sameFromLeft;
 70+ while ( sameFromRight < l && oldText[oldText.length - 1 - sameFromRight] == newText[newText.length - 1 - sameFromRight] ) {
 71+ ++sameFromRight;
 72+ }
 73+ }
 74+
 75+ console.log('sameFromLeft: ' + sameFromLeft);
 76+ console.log('sameFromRight: ' + sameFromRight);
 77+
 78+ if ( sameFromLeft + sameFromRight !== oldText.length ) {
 79+ var toDelete = oldText.split('');
 80+ console.log(toDelete.slice(sameFromLeft,oldText.length - sameFromRight).join(''));
 81+ }
 82+
 83+ if ( sameFromLeft + sameFromRight !== newText.length ) {
 84+ var toAdd = newText.split('');
 85+ console.log(toAdd.slice(sameFromLeft, newText.length - sameFromRight).join(''));
 86+ }
 87+
 88+
 89+
 90+
 91+
5792 </script>
5893 </head>
5994 <body>
Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js
@@ -30,6 +30,10 @@
3131 _this.emitUpdate( 25 );
3232 } );
3333
 34+ this.$.mousedown( function(e) {
 35+ return _this.onMouseDown( e );
 36+ } );
 37+
3438 this.$
3539 .on('cut copy', function(event) {
3640 var key = rangy.getSelection().getRangeAt(0).toString().replace(/( |\r\n|\n|\r|\t)/gm,"");
@@ -45,8 +49,8 @@
4650
4751 var selection = _this.getSelection();
4852 var tx = _this.model.getDocument().prepareRemoval( selection );
49 - _this.model.transact( tx );
50 - _this.showCursorAt(selection.start);
 53+ //_this.model.transact( tx );
 54+ //_this.showCursorAt(selection.start);
5155 }, 1);
5256 }
5357
@@ -75,10 +79,77 @@
7680
7781 // Initialization
7882 this.documentView.renderContent();
 83+
 84+ this.worker = null;
 85+ this.node = null;
7986 };
8087
8188 /* Methods */
8289
 90+ve.es.Surface.prototype.onMouseDown = function( e ) {
 91+ if ( this.worker !== null ) {
 92+ clearInterval( this.worker );
 93+ }
 94+
 95+ var _this = this;
 96+
 97+ setTimeout( function() {
 98+ _this.node = rangy.getSelection().anchorNode;
 99+ var prevText = _this.node.textContent;
 100+ _this.worker = setInterval( function() {
 101+ var text = _this.node.textContent;
 102+
 103+ if ( text === prevText ) {
 104+ return;
 105+ }
 106+
 107+ var nodeOffset = _this.getOffset( _this.node, 0 );
 108+
 109+ var sameFromLeft = 0,
 110+ sameFromRight = 0,
 111+ l = prevText.length;
 112+
 113+ while ( sameFromLeft < l && prevText[sameFromLeft] == text[sameFromLeft] ) {
 114+ ++sameFromLeft;
 115+ }
 116+ if ( prevText.length > sameFromLeft ) {
 117+ l = l - sameFromLeft;
 118+ while ( sameFromRight < l && prevText[prevText.length - 1 - sameFromRight] == text[text.length - 1 - sameFromRight] ) {
 119+ ++sameFromRight;
 120+ }
 121+ }
 122+
 123+ if ( sameFromLeft + sameFromRight !== prevText.length ) {
 124+ // delete
 125+ var range = new ve.Range( nodeOffset + sameFromLeft, nodeOffset + prevText.length - sameFromRight );
 126+ var tx = _this.model.getDocument().prepareRemoval( range );
 127+ _this.model.transact( tx );
 128+ }
 129+
 130+ if ( sameFromLeft + sameFromRight !== text.length ) {
 131+ // insert
 132+ var data = text.split('').slice(sameFromLeft, text.length - sameFromRight);
 133+ var tx = _this.documentView.model.prepareInsertion( nodeOffset + sameFromLeft, data);
 134+ _this.model.transact( tx );
 135+ }
 136+
 137+ prevText = text;
 138+ }, 50 );
 139+ }, 1 );
 140+
 141+
 142+ /*
 143+
 144+ var sel = rangy.getSelection();
 145+
 146+
 147+ if ( sel.anchorOffset === sel.focusOffset && sel.anchorNode === sel.focusNode ) {
 148+ console.log("123");
 149+ }
 150+
 151+ */
 152+};
 153+
83154 ve.es.Surface.prototype.attachContextView = function( contextView ) {
84155 this.contextView = contextView;
85156 };
@@ -104,6 +175,11 @@
105176
106177 ve.es.Surface.prototype.getOffset = function( localNode, localOffset ) {
107178 var $node = $( localNode );
 179+
 180+ if ( $node.hasClass( 'ce-leafNode' ) ) {
 181+ return this.documentView.getOffsetFromNode( $node.data('view') ) + 1;
 182+ }
 183+
108184 while( !$node.hasClass( 'ce-leafNode' ) ) {
109185 $node = $node.parent();
110186 }
Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Content.js
@@ -10,7 +10,7 @@
1111 // Events
1212 var _this = this;
1313 this.model.on( 'update', function( offset ) {
14 - _this.render( offset || 0 );
 14+ //_this.render( offset || 0 );
1515 } );
1616 }
1717 };

Status & tagging log