When pasting, try to use original range

This functionality was (accidentally?) removed by I8f8a240a. It
stops us from over-zealously balancing data when we can get away
with just pasting the original selected range (e.g. it always wraps
collections of text and content nodes in another paragraph).

Bug: 53364
Change-Id: I93fa56c4e43083993c310e0050087e9d1de1e08b
This commit is contained in:
Ed Sanders 2013-08-26 11:40:39 -07:00
parent fd410c03a7
commit ddb608e6bc

View file

@ -684,17 +684,35 @@ ve.ce.Surface.prototype.onPaste = function ( e ) {
)
);
}
pasteData = slice.getBalancedData();
// Annotate
ve.dm.Document.addAnnotationsToData( pasteData, this.model.getInsertionAnnotations() );
try {
// Try to paste in the orignal data
// Take a copy to prevent the data being annotated a second time in the catch block
pasteData = ve.copy( slice.getData() );
// Transaction
tx = ve.dm.Transaction.newFromInsertion(
view.documentView.model,
selection.start,
pasteData
);
// Annotate
ve.dm.Document.addAnnotationsToData( pasteData, this.model.getInsertionAnnotations() );
// Transaction
tx = ve.dm.Transaction.newFromInsertion(
view.documentView.model,
selection.start,
pasteData
);
} catch ( e ) {
// If that fails, balance the data before pasting
pasteData = slice.getBalancedData();
// Annotate
ve.dm.Document.addAnnotationsToData( pasteData, this.model.getInsertionAnnotations() );
// Transaction
tx = ve.dm.Transaction.newFromInsertion(
view.documentView.model,
selection.start,
pasteData
);
}
// Restore focus and scroll position
view.documentView.documentNode.$[0].focus();