r110905 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110904‎ | r110905 | r110906 >
Date:00:47, 8 February 2012
Author:christian
Status:deferred
Tags:
Comment:
copy and paste support
Modified paths:
  • /trunk/extensions/VisualEditor/cut-copy-paste.js (modified) (history)
  • /trunk/extensions/VisualEditor/demos/ce/index.php (modified) (history)
  • /trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/demos/ce/index.php
@@ -156,5 +156,7 @@
157157
158158 <!-- sandbox -->
159159 <script src="main.js"></script>
 160+
 161+ <div id="paste" contenteditable="true" style="height: 1px; width: 1px; position: absolute; left: -20000px;"></div>
160162 </body>
161163 </html>
Index: trunk/extensions/VisualEditor/cut-copy-paste.js
@@ -2,14 +2,21 @@
33 var paste = {};
44
55 $('#editor')
6 - .on('copy', function(event) {
 6+ .on('cut copy', function(event) {
 7+ console.log(event);
78 var range = rangy.getSelection().getRangeAt(0);
89 var key = range.toString().replace(/( |\r\n|\n|\r|\t)/gm,"");
910
1011 paste = {};
1112 paste[key] = 'some wikidom';
 13+
 14+ if (event.type == 'cut') {
 15+ console.log('tell model to cut from: ' + range.startOffset + ' to: ' + range.endOffset);
 16+ }
1217 })
1318 .on('beforepaste paste', function(event) {
 19+ console.log(event);
 20+
1421 $('#paste').html('');
1522 $('#paste').focus();
1623
Index: trunk/extensions/VisualEditor/modules/ve/ce/ve.es.Surface.js
@@ -19,6 +19,7 @@
2020 this.model = model;
2121 this.documentView = new ve.es.DocumentNode( this.model.getDocument(), this );
2222 this.contextView = null;
 23+ this.paste = {};
2324 this.$ = $container
2425 .addClass( 'es-surfaceView' )
2526 .append( this.documentView.$ );
@@ -29,6 +30,47 @@
3031 _this.emitUpdate( 25 );
3132 } );
3233
 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+
3375 // Initialization
3476 this.documentView.renderContent();
3577 };

Status & tagging log