Index: trunk/extensions/VisualEditor/modules/es/es.TransactionProcessor.js |
— | — | @@ -101,9 +101,16 @@ |
102 | 102 | remove = oldNodes.length; |
103 | 103 | } |
104 | 104 | } |
105 | | - parent.splice.apply( |
106 | | - parent, [index, remove].concat( es.DocumentModel.createNodesFromData( newData ) ) |
107 | | - ); |
| 105 | + // Try to perform this in a single operation if possible, this reduces the number of UI updates |
| 106 | + // TODO: Introduce a global for max argument length - 1024 is also assumed in es.insertIntoArray |
| 107 | + var newNodes = es.DocumentModel.createNodesFromData( newData ); |
| 108 | + if ( newNodes.length < 1024 ) { |
| 109 | + parent.splice.apply( parent, [index, remove].concat( newNodes ) ); |
| 110 | + } else { |
| 111 | + parent.splice.apply( parent, [index, remove] ); |
| 112 | + // Safe to call with arbitrary length of newNodes |
| 113 | + es.insertIntoArray( parent, index, newNodes ); |
| 114 | + } |
108 | 115 | }; |
109 | 116 | |
110 | 117 | es.TransactionProcessor.prototype.getScope = function( node, data ) { |