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

Revision: 110905
Author:   christian
Date:     2012-02-08 00:47:51 +0000 (Wed, 08 Feb 2012)
Log Message:
-----------
copy and paste support

Modified Paths:
--------------
    trunk/extensions/VisualEditor/cut-copy-paste.js
    trunk/extensions/VisualEditor/demos/ce/index.php
    trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js

Modified: trunk/extensions/VisualEditor/cut-copy-paste.js
===================================================================
--- trunk/extensions/VisualEditor/cut-copy-paste.js     2012-02-08 00:30:40 UTC 
(rev 110904)
+++ trunk/extensions/VisualEditor/cut-copy-paste.js     2012-02-08 00:47:51 UTC 
(rev 110905)
@@ -2,14 +2,21 @@
        var paste = {};
 
        $('#editor')
-               .on('copy', function(event) {
+               .on('cut copy', function(event) {
+                       console.log(event);
                        var range = rangy.getSelection().getRangeAt(0);
                        var key = range.toString().replace(/( 
|\r\n|\n|\r|\t)/gm,"");
 
                        paste = {};
                        paste[key] = 'some wikidom';
+                       
+                       if (event.type == 'cut') {
+                               console.log('tell model to cut from: ' + 
range.startOffset + ' to: ' + range.endOffset);
+                       }
                })
                .on('beforepaste paste', function(event) {
+                       console.log(event);
+
                        $('#paste').html('');
                        $('#paste').focus();
                        

Modified: trunk/extensions/VisualEditor/demos/ce/index.php
===================================================================
--- trunk/extensions/VisualEditor/demos/ce/index.php    2012-02-08 00:30:40 UTC 
(rev 110904)
+++ trunk/extensions/VisualEditor/demos/ce/index.php    2012-02-08 00:47:51 UTC 
(rev 110905)
@@ -156,5 +156,7 @@
 
                <!-- sandbox -->
                <script src="main.js"></script>
+               
+               <div id="paste" contenteditable="true" style="height: 1px; 
width: 1px; position: absolute; left: -20000px;"></div>
        </body>
 </html>

Modified: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js
===================================================================
--- trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js        
2012-02-08 00:30:40 UTC (rev 110904)
+++ trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js        
2012-02-08 00:47:51 UTC (rev 110905)
@@ -19,6 +19,7 @@
        this.model = model;
        this.documentView = new ve.es.DocumentNode( this.model.getDocument(), 
this );
        this.contextView = null;
+       this.paste = {};
        this.$ = $container
                .addClass( 'es-surfaceView' )
                .append( this.documentView.$ );
@@ -29,6 +30,47 @@
                _this.emitUpdate( 25 );
        } );
 
+       this.$  
+               .on('cut copy', function(event) {
+                       var key = 
rangy.getSelection().getRangeAt(0).toString().replace(/( |\r\n|\n|\r|\t)/gm,"");
+
+                       _this.paste[key] = ve.copyArray( 
_this.documentView.model.getData( _this.getSelection() ) );
+                       
+                       if (event.type == 'cut') {
+                               //not supported yet
+                               return;
+                               
+                               var range = _this.getSelection();
+                               if ( range.start != range.end ) {
+                                       event.preventDefault();
+                                       var tx = 
_this.model.getDocument().prepareRemoval( range );
+                                       _this.model.transact( tx );
+                               }
+
+                       }
+               })
+               .on('beforepaste paste', function(event) {
+                       var insertionPoint = _this.getSelection().to;
+                       
+                       $('#paste').html('');
+                       $('#paste').focus();
+                       
+                       setTimeout(function() {
+                               var key = $('#paste').text().replace(/( 
|\r\n|\n|\r|\t)/gm,"");
+                               
+                               if (_this.paste[key]) {
+                                       var tx = 
_this.documentView.model.prepareInsertion( insertionPoint, _this.paste[key]);
+                                       _this.documentView.model.commit(tx);
+                                       _this.showCursorAt(insertionPoint + 
_this.paste[key].length);
+                               } else {
+                                       alert('i can only handle copy/paste 
from hybrid surface. sorry. :(');
+                               }
+                               
+                       }, 1);
+               });
+               
+       
+
        // Initialization
        this.documentView.renderContent();
 };


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to