Support for pasting into a range

Change-Id: I13e29caba4d912db2477a2c3c4edeca5d21d06b4
This commit is contained in:
Christian Williams 2012-06-01 16:38:27 -07:00
parent 2bd615c6d2
commit cf63a2dd36

View file

@ -186,7 +186,7 @@ ve.ce.Surface.prototype.onCutCopy = function( e ) {
selection = _this.getSelectionRange(); selection = _this.getSelectionRange();
// Transact // 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 ); ve.dm.TransactionProcessor.commit( _this.documentView.model, tx );
// Place cursor // Place cursor
@ -200,7 +200,14 @@ ve.ce.Surface.prototype.onCutCopy = function( e ) {
*/ */
ve.ce.Surface.prototype.onPaste = function( e ) { ve.ce.Surface.prototype.onPaste = function( e ) {
var _this = this, 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(); $('#paste').html('').show().focus();
@ -220,12 +227,12 @@ ve.ce.Surface.prototype.onPaste = function( e ) {
// Transact // Transact
tx = ve.dm.Transaction.newFromInsertion( tx = ve.dm.Transaction.newFromInsertion(
_this.documentView.model, insertionPoint, pasteData _this.documentView.model, selection.start, pasteData
); );
ve.dm.TransactionProcessor.commit( _this.documentView.model, tx ); ve.dm.TransactionProcessor.commit( _this.documentView.model, tx );
// Place cursor // Place cursor
_this.showCursor( insertionPoint + pasteData.length ); _this.showCursor( selection.start + pasteData.length );
_this.documentView.documentNode.$.focus(); _this.documentView.documentNode.$.focus();
}, 1 ); }, 1 );
}; };