Skip to content

Commit

Permalink
[se] Fix traces-merge-optimization (#380)
Browse files Browse the repository at this point in the history
- Added an optimization fix for merging cells with active dependency lines
- Added mergeHelper object as a worksheet property
Co-authored-by: Dmitriy Orlov <[email protected]>
Co-committed-by: Dmitriy Orlov <[email protected]>
  • Loading branch information
DimitryOrlov authored and GoshaZotov committed Dec 5, 2024
1 parent 6b5d936 commit 85c2d58
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
26 changes: 17 additions & 9 deletions cell/model/FormulaObjects/traceDependents.js
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ function (window, undefined) {
}
}
};
TraceDependentsManager.prototype.changeDocument = function (prop, arg1, arg2) {
TraceDependentsManager.prototype.changeDocument = function (prop, arg1, arg2, fMergeCellIndex) {
switch (prop) {
case AscCommonExcel.docChangedType.cellValue:
if (this._lockChangeDocument) {
Expand Down Expand Up @@ -1595,23 +1595,31 @@ function (window, undefined) {
this._lockChangeDocument = true;
} else {
this._lockChangeDocument = null;
let t = this;
const t = this;
if (t.isHaveData() && arg2) {
if (Asc.c_oAscSelectionType.RangeMax === arg2.getType()) {
t.clearAll();
break;
}

let maxRowToClear = t.ws.nRowsCount ? Math.min(t.ws.nRowsCount, arg2.r2) : arg2.r2,
maxColToClear = t.ws.nColsCount ? Math.min(t.ws.nColsCount, arg2.c2) : arg2.c2;
let firstCellIndex = fMergeCellIndex !== undefined ? fMergeCellIndex : AscCommonExcel.getCellIndex(arg2.r1, arg2.c1);

for (let col = arg2.c1; col <= maxColToClear; col++) {
for (let row = arg2.r1; row <= maxRowToClear; row++) {
if (!(arg2.c1 === col && arg2.r1 === row)) {
t.clearCellTraces(row, col);
/* go through all existing dependencies and if they are in the merged range, delete them */
t.forEachDependents(function(i, precedents) {
for (let precedent in precedents) {
// delete everything except the first cell
if (precedent == firstCellIndex) {
continue;
}

let cell = AscCommonExcel.getFromCellIndex(precedent, true);
if (arg2.contains2(cell)) {
if (!(arg2.c1 === cell.col && arg2.r1 === cell.row)) {
t.clearCellTraces(cell.row, cell.col);
}
}
}
}
})
}
}
break;
Expand Down
22 changes: 20 additions & 2 deletions cell/model/Workbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -18773,6 +18773,7 @@
var oFirstCellHyperlink = null;

let error = false;
let firstMergeCellIndex;

this._setPropertyNoEmpty(null, null,
function(cell, nRow0, nCol0, nRowStart, nColStart) {
Expand All @@ -18790,6 +18791,9 @@
oFirstCellValue = cell.getValueData();
oFirstCellRow = cell.nRow;
oFirstCellCol = cell.nCol;

/* we write down the coordinates of the first cell with data, that we will skip when clearing dependencies */
firstMergeCellIndex = AscCommonExcel.getCellIndex(oFirstCellRow, oFirstCellCol);
}
}

Expand All @@ -18814,7 +18818,14 @@
return {errorType: error};
}

this.worksheet.workbook.handlers.trigger("changeDocument", AscCommonExcel.docChangedType.mergeRange, true, this.bbox, this.worksheet.getId());
this.worksheet.workbook.handlers.trigger(
"changeDocument",
AscCommonExcel.docChangedType.mergeRange,
true, /* arg1 */
this.bbox, /* arg2 */
this.worksheet.getId(),
firstMergeCellIndex
);
//правила работы с гиперссылками во время merge(отличются от Excel в случаем областей, например hyperlink: C3:D3 мержим C2:C3)
// 1)оставляем все ссылки, которые не полностью лежат в merge области
// 2)оставляем многоклеточные ссылки, top граница которых совпадает с top границей merge области, а высота merge > 1 или совпадает с высотой области merge
Expand Down Expand Up @@ -19025,7 +19036,14 @@
if (dataValidationRanges) {
this.worksheet.clearDataValidation(dataValidationRanges, true);
}
this.worksheet.workbook.handlers.trigger("changeDocument", AscCommonExcel.docChangedType.mergeRange, null, this.bbox, this.worksheet.getId());
this.worksheet.workbook.handlers.trigger(
"changeDocument",
AscCommonExcel.docChangedType.mergeRange,
null, /* arg1 */
this.bbox, /* arg2 */
this.worksheet.getId(),
firstMergeCellIndex
);

AscCommon.History.EndTransaction();
};
Expand Down
4 changes: 2 additions & 2 deletions cell/view/WorkbookView.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,11 +954,11 @@
ws.changeWorksheet("update", val);
}
});
this.model.handlers.add("changeDocument", function(prop, arg1, arg2, wsId) {
this.model.handlers.add("changeDocument", function(prop, arg1, arg2, wsId, fMergeCellIndex) {
self.SearchEngine && self.SearchEngine.changeDocument(prop, arg1, arg2);
let ws = wsId && self.getWorksheetById(wsId, true);
if (ws) {
ws.traceDependentsManager.changeDocument(prop, arg1, arg2);
ws.traceDependentsManager.changeDocument(prop, arg1, arg2, fMergeCellIndex);
}
});
this.model.handlers.add("showWorksheet", function(wsId) {
Expand Down

0 comments on commit 85c2d58

Please sign in to comment.