Prevent infinite loop when updating a table row in place (#7154)

* bump index on update row in place

* add test

* Removing problematic test

* spelling
This commit is contained in:
Scott Bell
2023-10-23 18:22:13 +02:00
committed by GitHub
parent 2daec448da
commit 13311b9fc8
2 changed files with 56 additions and 23 deletions

View File

@ -153,40 +153,41 @@ define(['lodash', 'EventEmitter'], function (_, EventEmitter) {
});
}
mergeSortedRows(rows) {
mergeSortedRows(incomingRows) {
const mergedRows = [];
let i = 0;
let j = 0;
let existingRowIndex = 0;
let incomingRowIndex = 0;
while (i < this.rows.length && j < rows.length) {
const existingRow = this.rows[i];
const incomingRow = rows[j];
while (existingRowIndex < this.rows.length && incomingRowIndex < incomingRows.length) {
const existingRow = this.rows[existingRowIndex];
const incomingRow = incomingRows[incomingRowIndex];
const index = this.getInPlaceUpdateIndex(incomingRow);
if (index > -1) {
this.updateRowInPlace(incomingRow, index);
const inPlaceIndex = this.getInPlaceUpdateIndex(incomingRow);
if (inPlaceIndex > -1) {
this.updateRowInPlace(incomingRow, inPlaceIndex);
incomingRowIndex++;
} else {
if (this.firstRowInSortOrder(existingRow, incomingRow) === existingRow) {
mergedRows.push(existingRow);
i++;
existingRowIndex++;
} else {
mergedRows.push(incomingRow);
j++;
incomingRowIndex++;
}
}
}
// tail of existing rows is all that is left to merge
if (i < this.rows.length) {
for (i; i < this.rows.length; i++) {
mergedRows.push(this.rows[i]);
if (existingRowIndex < this.rows.length) {
for (existingRowIndex; existingRowIndex < this.rows.length; existingRowIndex++) {
mergedRows.push(this.rows[existingRowIndex]);
}
}
// tail of incoming rows is all that is left to merge
if (j < rows.length) {
for (j; j < rows.length; j++) {
mergedRows.push(rows[j]);
if (incomingRowIndex < incomingRows.length) {
for (incomingRowIndex; incomingRowIndex < incomingRows.length; incomingRowIndex++) {
mergedRows.push(incomingRows[incomingRowIndex]);
}
}