Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js |
— | — | @@ -30,49 +30,19 @@ |
31 | 31 | _this.emitUpdate( 25 ); |
32 | 32 | } ); |
33 | 33 | |
34 | | - this.$.mousedown( function(e) { |
| 34 | + this.$.mousedown( function( e ) { |
35 | 35 | return _this.onMouseDown( e ); |
36 | 36 | } ); |
37 | 37 | |
38 | | - this.$ |
39 | | - .on('cut copy', function(event) { |
40 | | - var key = rangy.getSelection().getRangeAt(0).toString().replace(/( |\r\n|\n|\r|\t)/gm,""); |
| 38 | + this.$.on('cut copy', function( e ) { |
| 39 | + _this.onCutCopy( e ); |
| 40 | + } ); |
41 | 41 | |
42 | | - _this.clipboard[key] = ve.copyArray( _this.documentView.model.getData( _this.getSelection() ) ); |
| 42 | + this.$.on('paste', function( e ) { |
| 43 | + _this.onPaste( e ); |
| 44 | + } ); |
43 | 45 | |
44 | | - if (event.type == 'cut') { |
45 | | - setTimeout(function() { |
46 | | - document.execCommand('undo', false, false); |
47 | | - |
48 | | - var selection = _this.getSelection(); |
49 | | - var tx = _this.model.getDocument().prepareRemoval( selection ); |
50 | | - _this.model.transact( tx ); |
51 | | - _this.showCursorAt(selection.start); |
52 | | - }, 1); |
53 | | - } |
54 | | - |
55 | | - }) |
56 | | - .on('paste', function(event) { |
57 | | - var insertionPoint = _this.getSelection().start; |
58 | | - |
59 | | - $('#paste').html('').show().css('top', $(window).scrollTop()).css('left', $(window).scrollLeft()).focus(); |
60 | | - |
61 | | - setTimeout(function() { |
62 | | - var key = $('#paste').hide().text().replace(/( |\r\n|\n|\r|\t)/gm,""); |
63 | 46 | |
64 | | - if (_this.clipboard[key]) { |
65 | | - var tx = _this.documentView.model.prepareInsertion( insertionPoint, _this.clipboard[key]); |
66 | | - _this.model.transact( tx ); |
67 | | - _this.showCursorAt(insertionPoint + _this.clipboard[key].length); |
68 | | - } else { |
69 | | - alert('i can only handle copy/paste from hybrid surface. sorry. :('); |
70 | | - } |
71 | | - |
72 | | - }, 1); |
73 | | - }); |
74 | | - |
75 | | - |
76 | | - |
77 | 47 | // Initialization |
78 | 48 | this.documentView.renderContent(); |
79 | 49 | |
— | — | @@ -82,6 +52,44 @@ |
83 | 53 | |
84 | 54 | /* Methods */ |
85 | 55 | |
| 56 | +ve.es.Surface.prototype.onCutCopy = function( e ) { |
| 57 | + var _this = this, |
| 58 | + key = rangy.getSelection().getRangeAt(0).toString().replace(/( |\r\n|\n|\r|\t)/gm,""); |
| 59 | + |
| 60 | + _this.clipboard[key] = ve.copyArray( _this.documentView.model.getData( _this.getSelection() ) ); |
| 61 | + |
| 62 | + if ( event.type == 'cut' ) { |
| 63 | + setTimeout( function() { |
| 64 | + document.execCommand('undo', false, false); |
| 65 | + |
| 66 | + var selection = _this.getSelection(); |
| 67 | + var tx = _this.model.getDocument().prepareRemoval( selection ); |
| 68 | + _this.model.transact( tx ); |
| 69 | + _this.showCursorAt( selection.start ); |
| 70 | + }, 1 ); |
| 71 | + } |
| 72 | +}; |
| 73 | + |
| 74 | +ve.es.Surface.prototype.onPaste = function( e ) { |
| 75 | + var _this = this, |
| 76 | + insertionPoint = _this.getSelection().start; |
| 77 | + |
| 78 | + $('#paste').html('').show().css('top', $(window).scrollTop()).css('left', $(window).scrollLeft()).focus(); |
| 79 | + |
| 80 | + setTimeout( function() { |
| 81 | + var key = $('#paste').hide().text().replace(/( |\r\n|\n|\r|\t)/gm,""); |
| 82 | + |
| 83 | + if ( _this.clipboard[key] ) { |
| 84 | + var tx = _this.documentView.model.prepareInsertion( insertionPoint, _this.clipboard[key]); |
| 85 | + _this.model.transact( tx ); |
| 86 | + _this.showCursorAt(insertionPoint + _this.clipboard[key].length); |
| 87 | + } else { |
| 88 | + alert('i can only handle copy/paste from hybrid surface. sorry. :('); |
| 89 | + } |
| 90 | + |
| 91 | + }, 1 ); |
| 92 | +}; |
| 93 | + |
86 | 94 | ve.es.Surface.prototype.onMouseDown = function( e ) { |
87 | 95 | if ( this.worker !== null ) { |
88 | 96 | clearInterval( this.worker ); |