Commit f57d13a9 authored by Alexander.Trofimov's avatar Alexander.Trofimov

add function getRangeByRef

findCell based on getRangeByRef
delete findCell in WorkbookView
parent a1f9e6d7
...@@ -2038,19 +2038,14 @@ var editor; ...@@ -2038,19 +2038,14 @@ var editor;
if (this.asc_getCellEditMode()) { if (this.asc_getCellEditMode()) {
return; return;
} }
var d = this.wb.findCell(reference); var ws = this.wb.getWorksheet();
var d = ws.findCell(reference, this.isViewMode);
if (!d) { if (!d) {
if (!this.isViewMode) {
this.handlers.trigger("asc_onError", c_oAscError.ID.InvalidReferenceOrName, c_oAscError.Level.NoCritical);
}
return;
}
if (d.new) {
return; return;
} }
// Получаем sheet по имени // Получаем sheet по имени
var ws = this.wbModel.getWorksheetByName(d.sheet); ws = d.getWorksheet();
if (!ws || ws.getHidden()) { if (!ws || ws.getHidden()) {
return; return;
} }
...@@ -2065,17 +2060,12 @@ var editor; ...@@ -2065,17 +2060,12 @@ var editor;
} }
ws = this.wb.getWorksheet(); ws = this.wb.getWorksheet();
d = d.range ? ws.setSelectionUndoRedo(d.range, true) : null; d = ws.setSelectionUndoRedo(d.getBBox0(), true);
if (d.deltaX) {
if (d) { this.controller.scrollHorizontal(d.deltaX);
if (d.deltaX) { }
this.controller.scrollHorizontal(d.deltaX); if (d.deltaY) {
} this.controller.scrollVertical(d.deltaY);
if (d.deltaY) {
this.controller.scrollVertical(d.deltaY);
}
} else {
this.handlers.trigger("asc_onError", c_oAscError.ID.InvalidReferenceOrName, c_oAscError.Level.NoCritical);
} }
}; };
......
...@@ -2965,6 +2965,32 @@ var cFormulaOperators = { ...@@ -2965,6 +2965,32 @@ var cFormulaOperators = {
} }
return list; return list;
} }
function getRangeByRef(ref, ws) {
var range = null;
var _f = new AscCommonExcel.parserFormula(ref, '', ws);
_f.parse();
_f.RefPos.some(function (item) {
var ref;
switch (item.oper.type) {
case cElementType.table:
case cElementType.name:
ref = item.oper.toRef();
break;
case cElementType.cell:
case cElementType.cell3D:
case cElementType.cellsRange:
case cElementType.cellsRange3D:
ref = item.oper;
break;
}
if (ref && cElementType.error !== ref.type) {
range = ref.getRange();
return true;
}
return false;
});
return range;
}
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
...@@ -5569,6 +5595,7 @@ function rtl_math_erfc( x ) { ...@@ -5569,6 +5595,7 @@ function rtl_math_erfc( x ) {
window['AscCommonExcel'].cFormulaFunctionToLocale = null; window['AscCommonExcel'].cFormulaFunctionToLocale = null;
window['AscCommonExcel'].getFormulasInfo = getFormulasInfo; window['AscCommonExcel'].getFormulasInfo = getFormulasInfo;
window['AscCommonExcel'].getRangeByRef = getRangeByRef;
window['AscCommonExcel']._func = _func; window['AscCommonExcel']._func = _func;
......
...@@ -2268,11 +2268,6 @@ ...@@ -2268,11 +2268,6 @@
} }
}; };
// Поиск ячейки по ссылке
WorkbookView.prototype.findCell = function(reference) {
return this.getWorksheet().findCell(reference, this.controller.settings.isViewerMode);
};
WorkbookView.prototype.getDefinedNames = function(defNameListId) { WorkbookView.prototype.getDefinedNames = function(defNameListId) {
return this.model.getDefinedNamesWB(defNameListId); return this.model.getDefinedNamesWB(defNameListId);
}; };
......
...@@ -9548,29 +9548,31 @@ ...@@ -9548,29 +9548,31 @@
this.collaborativeEditing.onEndCheckLock( callback ); this.collaborativeEditing.onEndCheckLock( callback );
}; };
WorksheetView.prototype._isLockedDefNames = function ( callback, defNameId ) { WorksheetView.prototype._isLockedDefNames = function (callback, defNameId) {
var sheetId = this.model.getId(); var lockInfo = this.collaborativeEditing.getLockInfo(c_oAscLockTypeElem.Object, null
var lockInfo = this.collaborativeEditing.getLockInfo( c_oAscLockTypeElem.Object, null/*c_oAscLockTypeElemSubType.DefinedNames*/, -1, defNameId ); /*c_oAscLockTypeElemSubType.DefinedNames*/, -1, defNameId);
if ( false === this.collaborativeEditing.getCollaborativeEditing() ) { if (false === this.collaborativeEditing.getCollaborativeEditing()) {
// Пользователь редактирует один: не ждем ответа, а сразу продолжаем редактирование // Пользователь редактирует один: не ждем ответа, а сразу продолжаем редактирование
asc_applyFunction( callback, true ); asc_applyFunction(callback, true);
callback = undefined; callback = undefined;
} }
if ( false !== this.collaborativeEditing.getLockIntersection( lockInfo, c_oAscLockTypes.kLockTypeMine, /*bCheckOnlyLockAll*/false ) ) { if (false !==
this.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeMine, /*bCheckOnlyLockAll*/
false)) {
// Редактируем сами // Редактируем сами
asc_applyFunction( callback, true ); asc_applyFunction(callback, true);
return; return;
} } else if (false !== this.collaborativeEditing.getLockIntersection(lockInfo, c_oAscLockTypes.kLockTypeOther,
else if ( false !== this.collaborativeEditing.getLockIntersection( lockInfo, c_oAscLockTypes.kLockTypeOther, /*bCheckOnlyLockAll*/false ) ) { /*bCheckOnlyLockAll*/false)) {
// Уже ячейку кто-то редактирует // Уже ячейку кто-то редактирует
asc_applyFunction( callback, false ); asc_applyFunction(callback, false);
return; return;
} }
this.collaborativeEditing.onStartCheckLock(); this.collaborativeEditing.onStartCheckLock();
this.collaborativeEditing.addCheckLock( lockInfo ); this.collaborativeEditing.addCheckLock(lockInfo);
this.collaborativeEditing.onEndCheckLock( callback ); this.collaborativeEditing.onEndCheckLock(callback);
}; };
// Залочен ли весь лист // Залочен ли весь лист
...@@ -10574,71 +10576,30 @@ ...@@ -10574,71 +10576,30 @@
this._isLockedCells(aReplaceCells[options.indexInArray], /*subType*/null, onReplaceCallback); this._isLockedCells(aReplaceCells[options.indexInArray], /*subType*/null, onReplaceCallback);
}; };
WorksheetView.prototype.findCell = function (reference, isViewerMode) { WorksheetView.prototype.findCell = function (reference, isViewMode) {
var mc, bNew = false; var mc, range = AscCommonExcel.getRangeByRef(reference, this.model);
var range = AscCommonExcel.g_oRangeCache.getRange3D(reference) ||
AscCommonExcel.g_oRangeCache.getAscRange(reference);
if (!range) {
if (isViewerMode) {
return range;
}
if (!range && !isViewMode) {
/*TODO: сделать поиск по названиям автофигур, должен искать до того как вызвать поиск по именованным диапазонам*/ /*TODO: сделать поиск по названиям автофигур, должен искать до того как вызвать поиск по именованным диапазонам*/
var defName = this.model.workbook.getDefinesNames(reference, if (this.collaborativeEditing.getGlobalLock() || !this.handlers.trigger("getLockDefNameManagerStatus")) {
this.model.workbook.getActiveWs().getId()), sheetName, ref; this.handlers.trigger("onErrorEvent", c_oAscError.ID.LockCreateDefName, c_oAscError.Level.NoCritical);
if (!defName) { this._updateSelectionNameAndInfo();
if (this.collaborativeEditing.getGlobalLock() || return true;
!this.handlers.trigger("getLockDefNameManagerStatus")) { }
this.handlers.trigger("onErrorEvent", c_oAscError.ID.LockCreateDefName,
c_oAscError.Level.NoCritical);
this._updateSelectionNameAndInfo();
return true;
}
// ToDo multiselect defined names // ToDo multiselect defined names
var selectionLast = this.model.selectionRange.getLast(); var selectionLast = this.model.selectionRange.getLast();
mc = selectionLast.isOneCell() ? this.model.getMergedByCell(selectionLast.r1, selectionLast.c1) : null; mc = selectionLast.isOneCell() ? this.model.getMergedByCell(selectionLast.r1, selectionLast.c1) : null;
defName = this.model.workbook.editDefinesNames(null, var defName = this.model.workbook.editDefinesNames(null,
new Asc.asc_CDefName(reference, parserHelp.get3DRef(this.model.getName(), new Asc.asc_CDefName(reference, parserHelp.get3DRef(this.model.getName(),
(mc || selectionLast).getAbsName()))); (mc || selectionLast).getAbsName())));
bNew = true;
}
if (defName) { if (defName) {
range = true;
this._isLockedDefNames(null, defName.nodeId); this._isLockedDefNames(null, defName.nodeId);
} else {
if (defName.isTable) { this.handlers.trigger("asc_onError", c_oAscError.ID.InvalidReferenceOrName,
sheetName = defName.Ref.split("!"); c_oAscError.Level.NoCritical);
ref = sheetName[1];
sheetName = sheetName[0];
if (sheetName[0] == "'" && sheetName[sheetName.length - 1] == "'") {
sheetName = sheetName.substring(1, sheetName.length - 1);
}
range = AscCommonExcel.g_oRangeCache.getAscRange(ref);
sheetName = this.model.workbook.getWorksheetByName(sheetName);
} else if (defName.parsedRef.RefPos.length == 1 && defName.parsedRef.outStack.length == 1) {
ref = defName.parsedRef.outStack[0];
if (ref.type == AscCommonExcel.cElementType.cell3D) {
range = ref.range.getBBox0().clone(true);
sheetName = ref.getWS();
} else if (ref.type == AscCommonExcel.cElementType.cellsRange3D && ref.wsFrom == ref.wsTo) {
range = ref.getRange()[0].getBBox0().clone(true);
sheetName = this.model.workbook.getWorksheetById(ref.wsFrom);
}
}
if (range && sheetName) {
range = range.normalize();
mc = range.isOneCell() ? sheetName.getMergedByCell(range.r1, range.c1) : null;
range = {range: mc ? mc : range, sheet: sheetName.getName(), new: bNew};
}
} }
} else {
range = range.normalize();
mc = range.isOneCell() ? this.model.getMergedByCell(range.r1, range.c1) : null;
range = {range: mc ? mc : range, sheet: this.model.getName()};
} }
return range; return range;
}; };
......
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