r110811 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110810‎ | r110811 | r110812 >
Date:00:21, 7 February 2012
Author:christian
Status:deferred
Tags:nodeploy, visualeditor 
Comment:
work on copying and pasting
Modified paths:
  • /trunk/extensions/VisualEditor/contentEditable/views/es.SurfaceView.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/contentEditable/views/es.SurfaceView.js
@@ -8,6 +8,7 @@
99 // Properties
1010 this.model = model;
1111 this.documentView = new es.DocumentView( this.model.getDocument(), this );
 12+ this.paste = {};
1213 this.$ = $container
1314 .addClass( 'es-surfaceView' )
1415 .append( this.documentView.$ );
@@ -26,8 +27,41 @@
2728 } );
2829
2930 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+ });
3063 };
3164
 65+
3266 es.SurfaceView.prototype.onKeyDown = function( e ) {
3367 if ( e.which === 13 ) {
3468 e.preventDefault();

Status & tagging log