Commit 210979b8 authored by Alexander.Trofimov's avatar Alexander.Trofimov

fix merge and hidden in offset in selection

parent 53d11c62
...@@ -3343,7 +3343,7 @@ function Woorksheet(wb, _index, sId){ ...@@ -3343,7 +3343,7 @@ function Woorksheet(wb, _index, sId){
this.aSparklineGroups = []; this.aSparklineGroups = [];
this.selectionRange = new AscCommonExcel.SelectionRange(); this.selectionRange = new AscCommonExcel.SelectionRange(this);
/*handlers*/ /*handlers*/
this.handlers = null; this.handlers = null;
...@@ -3490,7 +3490,7 @@ Woorksheet.prototype.clone=function(sNewId, sName, tableNames){ ...@@ -3490,7 +3490,7 @@ Woorksheet.prototype.clone=function(sNewId, sName, tableNames){
if (this.sheetPr) if (this.sheetPr)
oNewWs.sheetPr = this.sheetPr.clone(); oNewWs.sheetPr = this.sheetPr.clone();
oNewWs.selectionRange = this.selectionRange.clone(); oNewWs.selectionRange = this.selectionRange.clone(oNewWs);
return oNewWs; return oNewWs;
}; };
......
...@@ -563,10 +563,12 @@ ...@@ -563,10 +563,12 @@
/** /**
* @constructor * @constructor
*/ */
function SelectionRange() { function SelectionRange(ws) {
this.ranges = [new Range(0, 0, 0, 0)]; this.ranges = [new Range(0, 0, 0, 0)];
this.activeCell = new AscCommon.CellBase(0, 0); // Active cell this.activeCell = new AscCommon.CellBase(0, 0); // Active cell
this.activeCellId = 0; this.activeCellId = 0;
this.worksheet = ws;
} }
SelectionRange.prototype.clean = function () { SelectionRange.prototype.clean = function () {
...@@ -598,14 +600,16 @@ ...@@ -598,14 +600,16 @@
this.activeCellId = -1; this.activeCellId = -1;
this.activeCell.clean(); this.activeCell.clean();
}; };
SelectionRange.prototype.offsetCell = function (dr, dc) { SelectionRange.prototype.offsetCell = function (dr, dc, fCheckSize) {
var curRange; var done, curRange, mc;
var lastRow = this.activeCell.row; var lastRow = this.activeCell.row;
var lastCol = this.activeCell.col; var lastCol = this.activeCell.col;
this.activeCell.row += dr; this.activeCell.row += dr;
this.activeCell.col += dc; this.activeCell.col += dc;
while (true) { while (!done) {
done = true;
curRange = this.ranges[this.activeCellId]; curRange = this.ranges[this.activeCellId];
if (!curRange.contains2(this.activeCell)) { if (!curRange.contains2(this.activeCell)) {
if (dr) { if (dr) {
...@@ -645,7 +649,45 @@ ...@@ -645,7 +649,45 @@
} }
} }
// ToDo merge and hidden mc = this.worksheet.getMergedByCell(this.activeCell.row, this.activeCell.col);
if (mc) {
if (dc > 0 && (this.activeCell.col > mc.c1 || this.activeCell.row !== mc.r1)) {
// Движение слева направо
this.activeCell.col = mc.c2 + 1;
done = false;
} else if (dc < 0 && (this.activeCell.col < mc.c2 || this.activeCell.row !== mc.r1)) {
// Движение справа налево
this.activeCell.col = mc.c1 - 1;
done = false;
}
if (dr > 0 && (this.activeCell.row > mc.r1 || this.activeCell.col !== mc.c1)) {
// Движение сверху вниз
this.activeCell.row = mc.r2 + 1;
done = false;
} else if (dr < 0 && (this.activeCell.row < mc.r2 || this.activeCell.col !== mc.c1)) {
// Движение снизу вверх
this.activeCell.row = mc.r1 - 1;
done = false;
}
}
if (!done) {
continue;
}
while (this.activeCell.col >= curRange.c1 && this.activeCell.col <= curRange.c2 && fCheckSize(0, this.activeCell.col)) {
this.activeCell.col += dc || (dr > 0 ? +1 : -1);
done = false;
}
if (!done) {
continue;
}
while (this.activeCell.row >= curRange.r1 && this.activeCell.row <= curRange.r2 && fCheckSize(this.activeCell.row, 0)) {
this.activeCell.row += dr || (dc > 0 ? +1 : -1);
done = false;
}
break; break;
} }
return (lastRow !== this.activeCell.row || lastCol !== this.activeCell.col) return (lastRow !== this.activeCell.row || lastCol !== this.activeCell.col)
......
...@@ -6572,13 +6572,15 @@ ...@@ -6572,13 +6572,15 @@
// Движение активной ячейки в выделенной области // Движение активной ячейки в выделенной области
WorksheetView.prototype._moveActivePointInSelection = function (dc, dr) { WorksheetView.prototype._moveActivePointInSelection = function (dc, dr) {
var cell = this.model.selectionRange.activeCell; var t = this, cell = this.model.selectionRange.activeCell;
// Если мы на скрытой строке или ячейке, то двигаться в выделении нельзя (так делает и Excel) // Если мы на скрытой строке или ячейке, то двигаться в выделении нельзя (так делает и Excel)
if (this.width_1px > this.cols[cell.col].width || this.height_1px > this.rows[cell.row].height) { if (this.width_1px > this.cols[cell.col].width || this.height_1px > this.rows[cell.row].height) {
return; return;
} }
return this.model.selectionRange.offsetCell(dr, dc); return this.model.selectionRange.offsetCell(dr, dc, function(row, col) {
return (0 <= row) ? (t.rows[row].height < t.height_1px) : (t.cols[col].width < t.width_1px);
});
var ar = this.activeRange; var ar = this.activeRange;
var arn = this.activeRange.clone(true); var arn = this.activeRange.clone(true);
...@@ -6865,22 +6867,23 @@ ...@@ -6865,22 +6867,23 @@
}; };
// Потеряем ли мы что-то при merge ячеек // Потеряем ли мы что-то при merge ячеек
WorksheetView.prototype.getSelectionMergeInfo = function ( options ) { WorksheetView.prototype.getSelectionMergeInfo = function (options) {
var arn = this.activeRange.clone( true ); // ToDo now check only last selection range
var arn = this.model.selectionRange.getLast().clone(true);
var notEmpty = false; var notEmpty = false;
var r, c; var r, c;
if ( this.cellCommentator.isMissComments( arn ) ) { if (this.cellCommentator.isMissComments(arn)) {
return true; return true;
} }
switch ( options ) { switch (options) {
case c_oAscMergeOptions.Merge: case c_oAscMergeOptions.Merge:
case c_oAscMergeOptions.MergeCenter: case c_oAscMergeOptions.MergeCenter:
for ( r = arn.r1; r <= arn.r2; ++r ) { for (r = arn.r1; r <= arn.r2; ++r) {
for ( c = arn.c1; c <= arn.c2; ++c ) { for (c = arn.c1; c <= arn.c2; ++c) {
if ( false === this._isCellEmptyText( c, r ) ) { if (false === this._isCellEmptyText(c, r)) {
if ( notEmpty ) { if (notEmpty) {
return true; return true;
} }
notEmpty = true; notEmpty = true;
...@@ -6889,11 +6892,11 @@ ...@@ -6889,11 +6892,11 @@
} }
break; break;
case c_oAscMergeOptions.MergeAcross: case c_oAscMergeOptions.MergeAcross:
for ( r = arn.r1; r <= arn.r2; ++r ) { for (r = arn.r1; r <= arn.r2; ++r) {
notEmpty = false; notEmpty = false;
for ( c = arn.c1; c <= arn.c2; ++c ) { for (c = arn.c1; c <= arn.c2; ++c) {
if ( false === this._isCellEmptyText( c, r ) ) { if (false === this._isCellEmptyText(c, r)) {
if ( notEmpty ) { if (notEmpty) {
return true; return true;
} }
notEmpty = true; notEmpty = true;
......
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