From cf63a2dd36c29e314ee775893be0dfb84fd86f3b Mon Sep 17 00:00:00 2001 From: Christian Williams Date: Fri, 1 Jun 2012 16:38:27 -0700 Subject: [PATCH] Support for pasting into a range Change-Id: I13e29caba4d912db2477a2c3c4edeca5d21d06b4 --- modules/ve2/ce/ve.ce.Surface.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/ve2/ce/ve.ce.Surface.js b/modules/ve2/ce/ve.ce.Surface.js index 4dfe942d2c..bfaa6edff3 100644 --- a/modules/ve2/ce/ve.ce.Surface.js +++ b/modules/ve2/ce/ve.ce.Surface.js @@ -186,7 +186,7 @@ ve.ce.Surface.prototype.onCutCopy = function( e ) { selection = _this.getSelectionRange(); // Transact - var tx = ve.dm.Transaction.newFromRemoval( _this.documentView.model, selection ); + tx = ve.dm.Transaction.newFromRemoval( _this.documentView.model, selection ); ve.dm.TransactionProcessor.commit( _this.documentView.model, tx ); // Place cursor @@ -200,7 +200,14 @@ ve.ce.Surface.prototype.onCutCopy = function( e ) { */ ve.ce.Surface.prototype.onPaste = function( e ) { var _this = this, - insertionPoint = _this.getSelectionRange().start; + selection = this.getSelectionRange(), + tx = null; + + // Pasting into a range? Remove first. + if (!rangy.getSelection().isCollapsed) { + tx = ve.dm.Transaction.newFromRemoval( _this.documentView.model, selection ); + ve.dm.TransactionProcessor.commit( _this.documentView.model, tx ); + } $('#paste').html('').show().focus(); @@ -220,12 +227,12 @@ ve.ce.Surface.prototype.onPaste = function( e ) { // Transact tx = ve.dm.Transaction.newFromInsertion( - _this.documentView.model, insertionPoint, pasteData + _this.documentView.model, selection.start, pasteData ); ve.dm.TransactionProcessor.commit( _this.documentView.model, tx ); // Place cursor - _this.showCursor( insertionPoint + pasteData.length ); + _this.showCursor( selection.start + pasteData.length ); _this.documentView.documentNode.$.focus(); }, 1 ); };