Commit 07dc2444 authored by Alexander.Trofimov's avatar Alexander.Trofimov

add find in selection

bug 35003
parent 00af61e4
......@@ -2177,7 +2177,8 @@
this.isReplaceAll = false; // заменить все (если у нас замена)
// внутренние переменные
this.activeCell = null;
this.findInSelection = false;
this.selectionRange = null;
this.indexInArray = 0;
this.countFind = 0;
this.countReplace = 0;
......@@ -2199,7 +2200,8 @@
result.replaceWith = this.replaceWith;
result.isReplaceAll = this.isReplaceAll;
result.activeCell = this.activeCell ? this.activeCell.clone() : null;
result.findInSelection = this.findInSelection;
result.selectionRange = this.selectionRange ? this.selectionRange.clone() : null;
result.indexInArray = this.indexInArray;
result.countFind = this.countFind;
result.countReplace = this.countReplace;
......@@ -2210,7 +2212,7 @@
return result;
};
asc_CFindOptions.prototype.isEqual = function (obj) {
return null != obj && this.findWhat === obj.findWhat && this.scanByRows === obj.scanByRows &&
return obj && this.findWhat === obj.findWhat && this.scanByRows === obj.scanByRows &&
this.scanForward === obj.scanForward && this.isMatchCase === obj.isMatchCase &&
this.isWholeCell === obj.isWholeCell && this.scanOnOnlySheet === obj.scanOnOnlySheet &&
this.lookIn === obj.lookIn;
......
......@@ -2228,7 +2228,7 @@
// Поиск текста в листе
WorkbookView.prototype.findCellText = function(options) {
// Для поиска эта переменная не нужна (но она может остаться от replace)
options.activeCell = null;
options.selectionRange = null;
var ws = this.getWorksheet();
// Останавливаем ввод данных в редакторе ввода
......@@ -2290,7 +2290,9 @@
}
if (result) {
return ws.setSelection(result);
var ac = ws.model.selectionRange.activeCell;
return options.findInSelection ? ws.changeSelectionActivePoint(result.c1 - ac.col, result.r1 - ac.row) :
ws.setSelection(result);
}
this._cleanFindResults();
return null;
......
......@@ -10973,13 +10973,28 @@
if (true !== options.isMatchCase) {
options.findWhat = options.findWhat.toLowerCase();
}
var ar = options.activeCell ? options.activeCell : this.model.selectionRange.activeCell;
var selectionRange = options.selectionRange || this.model.selectionRange;
var lastRange = selectionRange.getLast();
var ar = selectionRange.activeCell;
var c = ar.col;
var r = ar.row;
var minC = 0;
var minR = 0;
var maxC = this.cols.length - 1;
var maxR = this.rows.length - 1;
var merge = this.model.getMergedByCell(r, c);
options.findInSelection = options.scanOnOnlySheet &&
!(selectionRange.isSingleRange() && (lastRange.isOneCell() || lastRange.isEqual(merge)));
var minC, minR, maxC, maxR;
if (options.findInSelection) {
minC = lastRange.c1;
minR = lastRange.r1;
maxC = lastRange.c2;
maxR = lastRange.r2;
} else {
minC = 0;
minR = 0;
maxC = this.cols.length - 1;
maxR = this.rows.length - 1;
}
var inc = options.scanForward ? +1 : -1;
var isEqual;
......@@ -11020,34 +11035,29 @@
// Продолжаем циклический поиск
if (options.scanForward) {
// Идем вперед с первой ячейки
minC = 0;
minR = 0;
if (options.scanByRows) {
c = -1;
r = 0;
maxC = this.cols.length - 1;
c = minC - 1;
r = minR;
maxR = ar.row;
} else {
c = 0;
r = -1;
c = minC;
r = minR - 1;
maxC = ar.col;
maxR = this.rows.length - 1;
}
} else {
// Идем назад с последней
c = this.cols.length - 1;
r = this.rows.length - 1;
c = maxC;
r = maxR;
if (options.scanByRows) {
minC = 0;
c = maxC + 1;
r = maxR;
minR = ar.row;
} else {
c = maxC;
r = maxR + 1;
minC = ar.col;
minR = 0;
}
maxC = this.cols.length - 1;
maxR = this.rows.length - 1;
}
while (findNextCell()) {
isEqual = this._isCellEqual(c, r, options);
......@@ -11059,7 +11069,7 @@
};
WorksheetView.prototype.replaceCellText = function (options, lockDraw, callback) {
if (true !== options.isMatchCase) {
if (!options.isMatchCase) {
options.findWhat = options.findWhat.toLowerCase();
}
......@@ -11068,11 +11078,13 @@
options.countReplace = 0;
var t = this;
var activeCell = this.model.selectionRange.activeCell.clone();
var activeCell;
var aReplaceCells = [];
if (options.isReplaceAll) {
var selectionRange = this.model.selectionRange.clone();
activeCell = selectionRange.activeCell;
var aReplaceCellsIndex = {};
options.activeCell = activeCell;
options.selectionRange = selectionRange;
var findResult, index;
while (true) {
findResult = t.findCellText(options);
......@@ -11089,14 +11101,13 @@
activeCell.row = findResult.r1;
}
} else {
activeCell = this.model.selectionRange.activeCell;
// Попробуем сначала найти
var isEqual = this._isCellEqual(activeCell.col, activeCell.row, options);
if (null === isEqual) {
return callback(options);
}
if (isEqual) {
aReplaceCells.push(isEqual);
}
}
if (0 > aReplaceCells.length) {
return callback(options);
......
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