Index: trunk/extensions/VisualEditor/contentEditable/views/es.SurfaceView.js |
— | — | @@ -8,6 +8,7 @@ |
9 | 9 | // Properties |
10 | 10 | this.model = model; |
11 | 11 | this.documentView = new es.DocumentView( this.model.getDocument(), this ); |
| 12 | + this.paste = {}; |
12 | 13 | this.$ = $container |
13 | 14 | .addClass( 'es-surfaceView' ) |
14 | 15 | .append( this.documentView.$ ); |
— | — | @@ -26,8 +27,41 @@ |
27 | 28 | } ); |
28 | 29 | |
29 | 30 | this.documentView.renderContent(); |
| 31 | + |
| 32 | + this.$.bind('cut copy', function(event) { |
| 33 | + var range = rangy.getSelection().getRangeAt(0); |
| 34 | + var key = range.toString().replace(/ /g,""); |
| 35 | + |
| 36 | + console.log(es.copyArray(_this.documentView.model.getData(_this.getSelection()))); |
| 37 | + _this.paste[key] = es.copyArray(_this.documentView.model.getData(_this.getSelection())); |
| 38 | + |
| 39 | + if (event.type == 'cut') { |
| 40 | + event.preventDefault(); |
| 41 | + console.log('need to tell the model to cut'); |
| 42 | + var range = _this.getSelection(); |
| 43 | + if ( range.start != range.end ) { |
| 44 | + var tx = _this.model.getDocument().prepareRemoval( range ); |
| 45 | + _this.model.transact( tx ); |
| 46 | + } |
| 47 | + } |
| 48 | + }); |
| 49 | + this.$.bind('paste', function(event) { |
| 50 | + event.preventDefault(); |
| 51 | + console.log(event); |
| 52 | + //console.log(event.originalEvent.clipboardData.getData('Text')); |
| 53 | + var key = event.originalEvent.clipboardData.getData('text/plain').replace(/( |\r\n|\n|\r)/gm,""); |
| 54 | + |
| 55 | + if (_this.paste[key]) { |
| 56 | + console.log(_this.paste[key]); |
| 57 | + var tx = _this.documentView.model.prepareInsertion( _this.getSelection().to, _this.paste[key]); |
| 58 | + _this.documentView.model.commit(tx); |
| 59 | + } else { |
| 60 | + console.log('copied from external source'); |
| 61 | + } |
| 62 | + }); |
30 | 63 | }; |
31 | 64 | |
| 65 | + |
32 | 66 | es.SurfaceView.prototype.onKeyDown = function( e ) { |
33 | 67 | if ( e.which === 13 ) { |
34 | 68 | e.preventDefault(); |