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

Revision: 112847
Author:   christian
Date:     2012-03-01 22:27:23 +0000 (Thu, 01 Mar 2012)
Log Message:
-----------
adding cut-copy-paste

Modified Paths:
--------------
    trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js

Modified: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js        
2012-03-01 22:21:50 UTC (rev 112846)
+++ trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js        
2012-03-01 22:27:23 UTC (rev 112847)
@@ -23,6 +23,7 @@
                .addClass( 'es-surfaceView' )
                .append( this.documentView.$ );
        this.emitUpdateTimeout = undefined;
+       this.clipboard = {};
 
        // Events
        this.documentView.$.bind( {
@@ -41,6 +42,15 @@
                }
        } );
 
+
+       this.$.on('cut copy', function( e ) {
+               _this.onCutCopy( e );
+       } );
+
+       this.$.on('paste', function( e ) {
+               _this.onPaste( e );
+       } );
+
        this.$.mousedown( function(e) {
 //             return _this.onMouseDown( e );
        } );
@@ -74,6 +84,62 @@
 
 /* Methods */
 
+ve.es.Surface.prototype.onCutCopy = function( e ) {
+       console.log('cut/copy');
+       var _this = this,
+       rangySel = rangy.getSelection(),
+       key = rangySel.getRangeAt(0).toString().replace(/( 
|\r\n|\n|\r|\t)/gm,"");
+
+       _this.clipboard[key] = ve.copyArray( _this.documentView.model.getData( 
_this.getSelection() ) );
+
+       if ( event.type == 'cut' ) {
+               setTimeout( function() {
+                       document.execCommand('undo', false, false);
+                       var selection = _this.getSelection();
+                       var tx = _this.model.getDocument().prepareRemoval( 
selection );
+                       _this.model.transact( tx );
+                       _this.showCursorAt( selection.start );
+               }, 1 );
+       }
+};
+
+ve.es.Surface.prototype.onPaste = function( e ) {
+       var _this = this,
+       insertionPoint = _this.getSelection().start,
+       node = rangy.getSelection().anchorNode;
+
+       $('#paste').html('').show().css( 'top', $(window).scrollTop() ).css(' 
left', $(window).scrollLeft() ).focus();
+
+       _this.stopPolling();
+
+       setTimeout( function() {
+
+               console.log('key is: ');
+               console.log(_this.clipboard);
+               console.log('paste is: ');
+               console.log( $('#paste').hide().text().replace(/( 
|\r\n|\n|\r|\t)/gm,"") );
+
+
+               var key = $('#paste').hide().text().replace(/( 
|\r\n|\n|\r|\t)/gm,"");
+
+               if ( _this.clipboard[key] ) {
+                       // transact
+                       var tx = _this.documentView.model.prepareInsertion( 
insertionPoint, _this.clipboard[key]);
+                       _this.model.transact( tx );
+
+                       // re-render
+                       _this.getLeafNode( node ).data( 'view' 
).renderContent();
+
+                       // place cursor
+                       _this.showCursorAt( insertionPoint + 
_this.clipboard[key].length );
+
+                       _this.startPolling();
+               } else {
+                       alert('i can only handle copy/paste from hybrid 
surface. sorry. :(');
+               }
+       }, 1 );
+};
+
 ve.es.Surface.prototype.onCompositionStart = function( e ) {
        this.stopPolling();
        var rangySel = rangy.getSelection();


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

Reply via email to