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

add find in selection

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