Commit f83afbce authored by konovalovsergey's avatar konovalovsergey

fix bug 32828

parent ad73291a
......@@ -895,7 +895,9 @@ CHistory.prototype.Get_DeleteIndex = function () {
DeleteIndex += 1;
}
}
DeleteIndex += 1; // Это на взаимное расположение Sheet. Пишется в каждой точке изменений.
}
if (DeleteIndex > 0 && this.workbook.undoRedoSheetView.IsChangedState()) {
DeleteIndex += 1;
}
return DeleteIndex;
};
......@@ -921,10 +923,15 @@ CHistory.prototype.GetSerializeArray = function()
for(var j = 0, length2 = point.Items.length; j < length2; ++j)
{
var elem = point.Items[j];
aPointChanges.push(new AscCommonExcel.UndoRedoItemSerializable(elem.Class, elem.Type, elem.SheetId, elem.Range, elem.Data, elem.LocalChange));
if (!elem.LocalChange) {
aPointChanges.push(new AscCommonExcel.UndoRedoItemSerializable(elem.Class, elem.Type, elem.SheetId, elem.Range, elem.Data, elem.LocalChange));
}
}
aRes.push(aPointChanges);
}
if (aRes.length > 0 && this.workbook.undoRedoSheetView.IsChangedState()) {
aPointChanges.push(new AscCommonExcel.UndoRedoItemSerializable(this.workbook.undoRedoSheetView, null, null, null, null, false));
}
return aRes;
};
//функция, которая перемещает последнее действие на первую позицию(в текущей точке)
......
......@@ -2591,6 +2591,8 @@
this.bs.WriteItem(c_oSer_SheetView.ShowGridLines, function(){oThis.memory.WriteBool(oSheetView.showGridLines);});
if (null !== oSheetView.showRowColHeaders)
this.bs.WriteItem(c_oSer_SheetView.ShowRowColHeaders, function(){oThis.memory.WriteBool(oSheetView.showRowColHeaders);});
if (null !== oSheetView.zoomScale)
this.bs.WriteItem(c_oSer_SheetView.ZoomScale, function(){oThis.memory.WriteLong(oSheetView.zoomScale);});
if (null !== oSheetView.pane && oSheetView.pane.isInit())
this.bs.WriteItem(c_oSer_SheetView.Pane, function(){oThis.WriteSheetViewPane(oSheetView.pane);});
if (null !== ws.selectionRange)
......@@ -6492,7 +6494,7 @@
} else if (c_oSer_SheetView.WorkbookViewId === type) {
this.stream.GetLong();
} else if (c_oSer_SheetView.ZoomScale === type) {
this.stream.GetLong();
oSheetView.asc_setZoomScale(this.stream.GetLong());
} else if (c_oSer_SheetView.ZoomScaleNormal === type) {
this.stream.GetLong();
} else if (c_oSer_SheetView.ZoomScalePageLayoutView === type) {
......
......@@ -3789,6 +3789,142 @@ UndoRedoAutoFilters.prototype = {
UndoRedoSparklines.prototype.UndoRedo = function (Type, Data, nSheetId, bUndo) {
};
function UndoRedoSheetView(wb) {
this.wb = wb;
this.lastState = null;
this.Id = AscCommon.g_oIdCounter.Get_NewId();
g_oTableId.Add(this, this.Id);
}
UndoRedoSheetView.prototype.Type = -1;
UndoRedoSheetView.prototype.Get_Id = function() {
return this.Id;
};
UndoRedoSheetView.prototype.SaveState = function() {
this.lastState = this._getState();
};
UndoRedoSheetView.prototype.IsChangedState = function() {
return true;
};
UndoRedoSheetView.prototype.Save_Changes = function(data, w) {
w.WriteLong(this.Type);
var diff = this._getDiffState(this.lastState, this._getState());
if (null != diff.active) {
w.WriteByte(0);
w.WriteString2(diff.active);
}
for (var sheetId in diff.sheets) {
var elem = diff.sheets[sheetId];
if (elem) {
w.WriteByte(1);
w.WriteString2(sheetId);
if (null != elem.zoom) {
w.WriteByte(2);
w.WriteLong(elem.zoom);
}
if (null != elem.select) {
w.WriteByte(3);
elem.select.WriteToBinary(w);
}
w.WriteByte(255);
}
}
w.WriteByte(255);
};
UndoRedoSheetView.prototype.Load_Changes = function(r) {
var state = {active: null, sheets: {}};
r.GetLong();
var type;
while ((type = r.GetByte()) !== 255) {
if (0 === type) {
state.active = r.GetString2();
} else if (1 === type) {
var sheetId = r.GetString2();
var ws = this.wb.getWorksheetById(sheetId);
var elem = {zoom: null, select: null};
var subType;
while ((subType = r.GetByte()) !== 255) {
if (2 == subType) {
elem.zoom = r.GetLong();
} else if (3 == subType) {
elem.select = new AscCommonExcel.SelectionRange(ws);
elem.select.ReadFromBinary(r);
}
}
state.sheets[sheetId] = elem;
}
}
this._setState(state);
};
UndoRedoSheetView.prototype._getState = function() {
var wsActive = this.wb.getActiveWs();
var res = {active: wsActive.getId(), sheets: {}};
for (var i = 0; i < this.wb.getWorksheetCount(); ++i) {
var ws = this.wb.getWorksheet(i);
res.sheets[ws.getId()] = {zoom: ws.sheetViews[0].zoomScale, select: ws.selectionRange.clone()};
}
return res;
};
UndoRedoSheetView.prototype._setState = function(state) {
if (window["NATIVE_EDITOR_ENJINE"]) {
if (null != state.active) {
var ws = this.wb.getWorksheetById(state.active);
if (ws) {
this.wb.setActive(ws.getIndex());
}
}
for (var sheetId in state.sheets) {
var elem = state.sheets[sheetId];
var ws = this.wb.getWorksheetById(sheetId);
if (elem && ws) {
if (null != elem.zoom) {
ws.sheetViews[0].asc_setZoomScale(elem.zoom);
}
if (null != elem.select) {
ws.selectionRange = elem.select;
}
}
}
}
};
UndoRedoSheetView.prototype._getDiffState = function(stateBase, stateCur) {
if (!stateCur) {
return stateBase;
}
if (!stateBase) {
return stateCur;
}
//always write stateCur.active to set active
var res = {active: stateCur.active, sheets: {}};
for (var sheetId in stateCur.sheets) {
var elemCur = stateCur.sheets[sheetId];
var elemBase = stateBase.sheets[sheetId];
if (!elemCur) {
res.sheets[sheetId] = elemBase;
continue;
}
if (!elemBase) {
res.sheets[sheetId] = elemCur;
continue;
}
var bAdd = false;
var elemNew = {zoom: null, select: null};
if (elemBase.zoom !== elemCur.zoom) {
bAdd = true;
elemNew.zoom = elemCur.zoom;
}
if (!elemBase.select.isEqual2(elemCur.select)) {
bAdd = true;
elemNew.select = elemCur.select;
}
if (bAdd) {
res.sheets[sheetId] = elemNew;
}
}
return res;
};
//----------------------------------------------------------export----------------------------------------------------
window['AscCommonExcel'] = window['AscCommonExcel'] || {};
window['AscCommonExcel'].UndoRedoItemSerializable = UndoRedoItemSerializable;
......@@ -3817,6 +3953,7 @@ UndoRedoAutoFilters.prototype = {
window['AscCommonExcel'].UndoRedoComment = UndoRedoComment;
window['AscCommonExcel'].UndoRedoAutoFilters = UndoRedoAutoFilters;
window['AscCommonExcel'].UndoRedoSparklines = UndoRedoSparklines;
window['AscCommonExcel'].UndoRedoSheetView = UndoRedoSheetView;
window['AscCommonExcel'].g_oUndoRedoWorkbook = null;
window['AscCommonExcel'].g_oUndoRedoCell = null;
......
......@@ -1389,6 +1389,7 @@
this.maxDigitWidth = 0;
this.paddingPlusBorder = 0;
this.undoRedoSheetView = null;
}
Workbook.prototype.init=function(tableCustomFunc, bNoBuildDep, bSnapshot){
if(this.nActive < 0)
......@@ -1432,6 +1433,8 @@
if (bSnapshot) {
this.snapshot = this._getSnapshot();
}
this.undoRedoSheetView = new AscCommonExcel.UndoRedoSheetView(this);
this.undoRedoSheetView.SaveState();
};
Workbook.prototype.rebuildColors=function(){
AscCommonExcel.g_oColorManager.rebuildColors();
......@@ -1881,6 +1884,7 @@
}
}
this.aCollaborativeActions = [];
this.undoRedoSheetView.SaveState();
this.snapshot = this._getSnapshot();
}
return aRes;
......
......@@ -867,6 +867,18 @@
return false;
// todo return this.activeCell.isEqual(range.cell);
};
SelectionRange.prototype.isEqual2 = function(range) {
if (this.activeCellId !== range.activeCellId || !this.activeCell.isEqual(range.activeCell) ||
this.ranges.length !== range.ranges.length) {
return false;
}
for (var i = 0; i < this.ranges.length; ++i) {
if (!this.ranges[i].isEqual(range.ranges[i])) {
return false;
}
}
return true;
};
SelectionRange.prototype.addRange = function () {
this.ranges.push(new Range(0, 0, 0, 0));
this.activeCellId = -1;
......@@ -1040,6 +1052,35 @@
this.activeCellId = this.ranges.length - 1;
}
};
SelectionRange.prototype.WriteToBinary = function(w) {
w.WriteLong(this.ranges.length);
for (var i = 0; i < this.ranges.length; ++i) {
var range = this.ranges[i];
w.WriteLong(range.c1);
w.WriteLong(range.r1);
w.WriteLong(range.c2);
w.WriteLong(range.r2);
}
w.WriteLong(this.activeCell.row);
w.WriteLong(this.activeCell.col);
w.WriteLong(this.activeCellId);
};
SelectionRange.prototype.ReadFromBinary = function(r) {
this.clean();
var count = r.GetLong();
var rangesNew = [];
for (var i = 0; i < count; ++i) {
var range = new Asc.Range(r.GetLong(), r.GetLong(), r.GetLong(), r.GetLong());
rangesNew.push(range);
}
if (rangesNew.length > 0) {
this.ranges = rangesNew;
}
this.activeCell.row = r.GetLong();
this.activeCell.col = r.GetLong();
this.activeCellId = r.GetLong();
this.update();
};
/**
*
......@@ -1786,6 +1827,9 @@
// Закрепление области
this.pane = null;
//current view zoom
this.zoomScale = 100;
return this;
}
......@@ -1795,6 +1839,7 @@
var result = new asc_CSheetViewSettings();
result.showGridLines = this.showGridLines;
result.showRowColHeaders = this.showRowColHeaders;
result.zoom = this.zoom;
if (this.pane)
result.pane = this.pane.clone();
return result;
......@@ -1805,9 +1850,11 @@
},
asc_getShowGridLines: function () { return false !== this.showGridLines; },
asc_getShowRowColHeaders: function () { return false !== this.showRowColHeaders; },
asc_getZoomScale: function () { return this.zoomScale; },
asc_getIsFreezePane: function () { return null !== this.pane && this.pane.isInit(); },
asc_setShowGridLines: function (val) { this.showGridLines = val; },
asc_setShowRowColHeaders: function (val) { this.showRowColHeaders = val; }
asc_setShowRowColHeaders: function (val) { this.showRowColHeaders = val; },
asc_setZoomScale: function (val) { this.zoomScale = val; }
};
/** @constructor */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment