EditCheck: catch errors from TransactionSquasher

Bug: T324733
Change-Id: I5076db530fa8af72a336916f8284e6f3348cfd38
This commit is contained in:
David Lynch 2023-04-03 12:51:41 -05:00
parent 20464f62c2
commit 9d3c048785

View file

@ -7,16 +7,22 @@ mw.editcheck.doesAddedContentNeedReference = function ( documentModel ) {
var ranges = []; var ranges = [];
var offset = 0; var offset = 0;
var endOffset = documentModel.getDocumentRange().end; var endOffset = documentModel.getDocumentRange().end;
documentModel.completeHistory.squash().transactions[ 0 ].operations.every( function ( op ) { try {
if ( op.type === 'retain' ) { documentModel.completeHistory.squash().transactions[ 0 ].operations.every( function ( op ) {
offset += op.length; if ( op.type === 'retain' ) {
} else if ( op.type === 'replace' ) { offset += op.length;
ranges.push( new ve.Range( offset, offset + op.insert.length ) ); } else if ( op.type === 'replace' ) {
offset += op.insert.length; ranges.push( new ve.Range( offset, offset + op.insert.length ) );
} offset += op.insert.length;
// Reached the end of the doc / start of internal list, stop searching }
return offset < endOffset; // Reached the end of the doc / start of internal list, stop searching
} ); return offset < endOffset;
} );
} catch ( e ) {
// TransactionSquasher can sometimes throw errors; until T333710 is
// fixed just count this as not needing a reference.
return false;
}
return ranges.some( function ( range ) { return ranges.some( function ( range ) {
var minimumCharacters = 50; var minimumCharacters = 50;
// 1. Check that at least minimumCharacters characters have been inserted sequentially // 1. Check that at least minimumCharacters characters have been inserted sequentially