Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js |
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | .addClass( 'es-surfaceView' ) |
25 | 25 | .append( this.documentView.$ ); |
26 | 26 | this.emitUpdateTimeout = undefined; |
| 27 | + this.clipboard = {}; |
27 | 28 | |
28 | 29 | // Events |
29 | 30 | this.documentView.$.bind( { |
— | — | @@ -41,6 +42,15 @@ |
42 | 43 | } |
43 | 44 | } ); |
44 | 45 | |
| 46 | + |
| 47 | + this.$.on('cut copy', function( e ) { |
| 48 | + _this.onCutCopy( e ); |
| 49 | + } ); |
| 50 | + |
| 51 | + this.$.on('paste', function( e ) { |
| 52 | + _this.onPaste( e ); |
| 53 | + } ); |
| 54 | + |
45 | 55 | this.$.mousedown( function(e) { |
46 | 56 | // return _this.onMouseDown( e ); |
47 | 57 | } ); |
— | — | @@ -74,6 +84,62 @@ |
75 | 85 | |
76 | 86 | /* Methods */ |
77 | 87 | |
| 88 | +ve.es.Surface.prototype.onCutCopy = function( e ) { |
| 89 | + console.log('cut/copy'); |
| 90 | + var _this = this, |
| 91 | + rangySel = rangy.getSelection(), |
| 92 | + key = rangySel.getRangeAt(0).toString().replace(/( |\r\n|\n|\r|\t)/gm,""); |
| 93 | + |
| 94 | + _this.clipboard[key] = ve.copyArray( _this.documentView.model.getData( _this.getSelection() ) ); |
| 95 | + |
| 96 | + if ( event.type == 'cut' ) { |
| 97 | + setTimeout( function() { |
| 98 | + document.execCommand('undo', false, false); |
| 99 | + var selection = _this.getSelection(); |
| 100 | + var tx = _this.model.getDocument().prepareRemoval( selection ); |
| 101 | + _this.model.transact( tx ); |
| 102 | + _this.showCursorAt( selection.start ); |
| 103 | + }, 1 ); |
| 104 | + } |
| 105 | +}; |
| 106 | + |
| 107 | +ve.es.Surface.prototype.onPaste = function( e ) { |
| 108 | + var _this = this, |
| 109 | + insertionPoint = _this.getSelection().start, |
| 110 | + node = rangy.getSelection().anchorNode; |
| 111 | + |
| 112 | + $('#paste').html('').show().css( 'top', $(window).scrollTop() ).css(' left', $(window).scrollLeft() ).focus(); |
| 113 | + |
| 114 | + _this.stopPolling(); |
| 115 | + |
| 116 | + setTimeout( function() { |
| 117 | + |
| 118 | + console.log('key is: '); |
| 119 | + console.log(_this.clipboard); |
| 120 | + console.log('paste is: '); |
| 121 | + console.log( $('#paste').hide().text().replace(/( |\r\n|\n|\r|\t)/gm,"") ); |
| 122 | + |
| 123 | + |
| 124 | + var key = $('#paste').hide().text().replace(/( |\r\n|\n|\r|\t)/gm,""); |
| 125 | + |
| 126 | + if ( _this.clipboard[key] ) { |
| 127 | + // transact |
| 128 | + var tx = _this.documentView.model.prepareInsertion( insertionPoint, _this.clipboard[key]); |
| 129 | + _this.model.transact( tx ); |
| 130 | + |
| 131 | + // re-render |
| 132 | + _this.getLeafNode( node ).data( 'view' ).renderContent(); |
| 133 | + |
| 134 | + // place cursor |
| 135 | + _this.showCursorAt( insertionPoint + _this.clipboard[key].length ); |
| 136 | + |
| 137 | + _this.startPolling(); |
| 138 | + } else { |
| 139 | + alert('i can only handle copy/paste from hybrid surface. sorry. :('); |
| 140 | + } |
| 141 | + }, 1 ); |
| 142 | +}; |
| 143 | + |
78 | 144 | ve.es.Surface.prototype.onCompositionStart = function( e ) { |
79 | 145 | this.stopPolling(); |
80 | 146 | var rangySel = rangy.getSelection(); |