[se] Make workbook changes unique; For bug 76642

This commit is contained in:
Sergey Konovalov
2025-10-09 18:07:01 +03:00
parent 2c54acedd7
commit b7b6a04838
3 changed files with 14 additions and 13 deletions

View File

@ -343,10 +343,12 @@ var editor;
}
};
spreadsheet_api.prototype.initGlobalObjects = function(wbModel) {
spreadsheet_api.prototype.initGlobalObjects = function(wbModel, fileSize) {
// global counters
AscCommonExcel.UndoRedoClassTypes.Clean();
// Use deterministic pseudo-random offset to make document changes unique (100 to fit in 1 byte)
AscCommonExcel.UndoRedoClassTypes.SetOffset((fileSize || 0) % 100);
AscCommonExcel.g_oUndoRedoCell = new AscCommonExcel.UndoRedoCell(wbModel);
AscCommonExcel.g_oUndoRedoWorksheet = new AscCommonExcel.UndoRedoWoorksheet(wbModel);
AscCommonExcel.g_oUndoRedoWorkbook = new AscCommonExcel.UndoRedoWorkbook(wbModel);
@ -1849,13 +1851,13 @@ var editor;
spreadsheet_api.prototype.OpenDocumentFromBin = function(url, gObject)
{
this.wbModel = new AscCommonExcel.Workbook(this.handlers, this, true);
this.initGlobalObjects(this.wbModel);
this.initGlobalObjects(this.wbModel, gObject.length);
this.OpenDocumentFromBinNoInit(gObject);
this._onEndOpen();
};
spreadsheet_api.prototype.OpenDocumentFromZip = function (data) {
this.wbModel = new AscCommonExcel.Workbook(this.handlers, this, true);
this.initGlobalObjects(this.wbModel);
this.initGlobalObjects(this.wbModel, data.length);
let res = this.OpenDocumentFromZipNoInit(data);
this._onEndOpen();
return res;
@ -6684,7 +6686,7 @@ var editor;
AscCommon.CurFileVersion = version;
}
this.wbModel = new AscCommonExcel.Workbook(this.handlers, this, true);
this.initGlobalObjects(this.wbModel);
this.initGlobalObjects(this.wbModel, base64File.length);
this.isOpenOOXInBrowser = this["asc_isSupportFeature"]("ooxml") && AscCommon.checkOOXMLSignature(base64File);
if (this.isOpenOOXInBrowser) {

View File

@ -10495,12 +10495,6 @@
var oThis = this;
if ( c_oSerWorksheetsTypes.Worksheet === type )
{
// Shift by deterministic pseudo-random offset to make document changes unique
if (AscCommon.g_oIdCounter.IsLoad()) {
for (let i = 0; i < length % 100; i++) {
AscCommon.g_oIdCounter.Get_NewId();
}
}
this.aMerged = [];
this.aHyperlinks = [];
var oNewWorksheet = new AscCommonExcel.Worksheet(this.wb, wb.aWorksheets.length);

View File

@ -2847,17 +2847,22 @@ function (window, undefined) {
//для применения изменений
var UndoRedoClassTypes = new function () {
this.aTypes = [];
this.offset = 0;
this.Add = function (fCreate) {
var nRes = this.aTypes.length;
this.aTypes.push(fCreate);
return nRes;
return nRes + this.offset;
};
this.Create = function (nType) {
if (nType < this.aTypes.length) {
return this.aTypes[nType]();
const nTypeIndex = nType - this.offset;
if (0 <= nTypeIndex && nTypeIndex < this.aTypes.length) {
return this.aTypes[nTypeIndex]();
}
return null;
};
this.SetOffset = function (offset) {
this.offset = offset || 0;
};
this.Clean = function () {
this.aTypes = [];
};