Index: trunk/extensions/VisualEditor/demos/ce/index.php |
— | — | @@ -156,5 +156,7 @@ |
157 | 157 | |
158 | 158 | <!-- sandbox --> |
159 | 159 | <script src="main.js"></script> |
| 160 | + |
| 161 | + <div id="paste" contenteditable="true" style="height: 1px; width: 1px; position: absolute; left: -20000px;"></div> |
160 | 162 | </body> |
161 | 163 | </html> |
Index: trunk/extensions/VisualEditor/cut-copy-paste.js |
— | — | @@ -2,14 +2,21 @@ |
3 | 3 | var paste = {}; |
4 | 4 | |
5 | 5 | $('#editor') |
6 | | - .on('copy', function(event) { |
| 6 | + .on('cut copy', function(event) { |
| 7 | + console.log(event); |
7 | 8 | var range = rangy.getSelection().getRangeAt(0); |
8 | 9 | var key = range.toString().replace(/( |\r\n|\n|\r|\t)/gm,""); |
9 | 10 | |
10 | 11 | paste = {}; |
11 | 12 | paste[key] = 'some wikidom'; |
| 13 | + |
| 14 | + if (event.type == 'cut') { |
| 15 | + console.log('tell model to cut from: ' + range.startOffset + ' to: ' + range.endOffset); |
| 16 | + } |
12 | 17 | }) |
13 | 18 | .on('beforepaste paste', function(event) { |
| 19 | + console.log(event); |
| 20 | + |
14 | 21 | $('#paste').html(''); |
15 | 22 | $('#paste').focus(); |
16 | 23 | |
Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js |
— | — | @@ -19,6 +19,7 @@ |
20 | 20 | this.model = model; |
21 | 21 | this.documentView = new ve.es.DocumentNode( this.model.getDocument(), this ); |
22 | 22 | this.contextView = null; |
| 23 | + this.paste = {}; |
23 | 24 | this.$ = $container |
24 | 25 | .addClass( 'es-surfaceView' ) |
25 | 26 | .append( this.documentView.$ ); |
— | — | @@ -29,6 +30,47 @@ |
30 | 31 | _this.emitUpdate( 25 ); |
31 | 32 | } ); |
32 | 33 | |
| 34 | + this.$ |
| 35 | + .on('cut copy', function(event) { |
| 36 | + var key = rangy.getSelection().getRangeAt(0).toString().replace(/( |\r\n|\n|\r|\t)/gm,""); |
| 37 | + |
| 38 | + _this.paste[key] = ve.copyArray( _this.documentView.model.getData( _this.getSelection() ) ); |
| 39 | + |
| 40 | + if (event.type == 'cut') { |
| 41 | + //not supported yet |
| 42 | + return; |
| 43 | + |
| 44 | + var range = _this.getSelection(); |
| 45 | + if ( range.start != range.end ) { |
| 46 | + event.preventDefault(); |
| 47 | + var tx = _this.model.getDocument().prepareRemoval( range ); |
| 48 | + _this.model.transact( tx ); |
| 49 | + } |
| 50 | + |
| 51 | + } |
| 52 | + }) |
| 53 | + .on('beforepaste paste', function(event) { |
| 54 | + var insertionPoint = _this.getSelection().to; |
| 55 | + |
| 56 | + $('#paste').html(''); |
| 57 | + $('#paste').focus(); |
| 58 | + |
| 59 | + setTimeout(function() { |
| 60 | + var key = $('#paste').text().replace(/( |\r\n|\n|\r|\t)/gm,""); |
| 61 | + |
| 62 | + if (_this.paste[key]) { |
| 63 | + var tx = _this.documentView.model.prepareInsertion( insertionPoint, _this.paste[key]); |
| 64 | + _this.documentView.model.commit(tx); |
| 65 | + _this.showCursorAt(insertionPoint + _this.paste[key].length); |
| 66 | + } else { |
| 67 | + alert('i can only handle copy/paste from hybrid surface. sorry. :('); |
| 68 | + } |
| 69 | + |
| 70 | + }, 1); |
| 71 | + }); |
| 72 | + |
| 73 | + |
| 74 | + |
33 | 75 | // Initialization |
34 | 76 | this.documentView.renderContent(); |
35 | 77 | }; |