Skip to content

Commit

Permalink
Feature/search callback (#2505)
Browse files Browse the repository at this point in the history
* Add callback for search function

* Use asc_findText instead of findText

* remove findText

Co-authored-by: Sergey Luzyanin <[email protected]>
  • Loading branch information
K0R0L and SergeyLuzyanin authored Jan 25, 2022
1 parent b3fce19 commit 517774c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 41 deletions.
17 changes: 10 additions & 7 deletions cell/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3003,20 +3003,23 @@ var editor;
spreadsheet_api.prototype.asc_searchEnabled = function(bIsEnabled) {
};

spreadsheet_api.prototype.asc_findText = function(options) {
spreadsheet_api.prototype.asc_findText = function(options, callback) {
var result = null;
if (window["NATIVE_EDITOR_ENJINE"]) {
if (this.wb.findCellText(options)) {
var ws = this.wb.getWorksheet();
var activeCell = this.wbModel.getActiveWs().selectionRange.activeCell;
return [ws.getCellLeftRelative(activeCell.col, 0), ws.getCellTopRelative(activeCell.row, 0)];
result = [ws.getCellLeftRelative(activeCell.col, 0), ws.getCellTopRelative(activeCell.row, 0)];
}

return null;
} else {
var d = this.wb.findCellText(options);
this.controller.scroll(d);
result = !!d;
}

var d = this.wb.findCellText(options);
this.controller.scroll(d);
return !!d;
if (callback)
callback(result);
return result;
};

spreadsheet_api.prototype.asc_replaceText = function(options) {
Expand Down
4 changes: 3 additions & 1 deletion common/Native/Wrappers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5182,7 +5182,7 @@ Asc['asc_docs_api'].prototype.SetDocumentModified = function(bValue)
};

// find -------------------------------------------------------------------------------------------------
Asc['asc_docs_api'].prototype.asc_findText = function(text, isNext, isMatchCase)
Asc['asc_docs_api'].prototype.asc_findText = function(text, isNext, isMatchCase, callback)
{
var SearchEngine = editor.WordControl.m_oLogicDocument.Search( text, { MatchCase : isMatchCase } );

Expand All @@ -5191,6 +5191,8 @@ Asc['asc_docs_api'].prototype.asc_findText = function(text, isNext, isMatchCase)
if ( null != Id )
this.WordControl.m_oLogicDocument.SelectSearchElement( Id );

if (callback)
callback(SearchEngine.Count);
return SearchEngine.Count;
};

Expand Down
17 changes: 10 additions & 7 deletions pdf/src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1650,25 +1650,28 @@
return this.file.copy(_text_format);
};

this.findText = function(text, isMachingCase, isNext)
this.findText = function(text, isMachingCase, isNext, callback)
{
if (this.isFullTextMessage)
return bRetValue;

if (!this.isFullText)
{
this.fullTextMessageCallbackArgs = [text, isMachingCase, isNext];
this.fullTextMessageCallbackArgs = [text, isMachingCase, isNext, callback];
this.fullTextMessageCallback = function() {
this.file.findText(this.fullTextMessageCallbackArgs[0], this.fullTextMessageCallbackArgs[1], this.fullTextMessageCallbackArgs[2]);
this.onUpdateOverlay();

if (this.fullTextMessageCallbackArgs[3])
this.fullTextMessageCallbackArgs[3](this.SearchResults.Count);
};
this.showTextMessage();
return true; // async
}
else
{
this.file.findText(text, isMachingCase, isNext);
this.onUpdateOverlay();
}

this.file.findText(text, isMachingCase, isNext);
this.onUpdateOverlay();
return false;
};

this.ToSearchResult = function()
Expand Down
31 changes: 13 additions & 18 deletions slide/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2408,21 +2408,6 @@ background-repeat: no-repeat;\
this.sendEvent("asc_onSearchEnd");
};

asc_docs_api.prototype.findText = function(text, isNext, isMatchCase)
{

var SearchEngine = editor.WordControl.m_oLogicDocument.Search(text, {MatchCase : isMatchCase});

var Id = this.WordControl.m_oLogicDocument.GetSearchElementId(isNext);

if (null != Id)
this.WordControl.m_oLogicDocument.SelectSearchElement(Id);

return SearchEngine.Count;

//return this.WordControl.m_oLogicDocument.findText(text, scanForward);
};

asc_docs_api.prototype.asc_replaceText = function(text, replaceWith, isReplaceAll, isMatchCase)
{
if (null == this.WordControl.m_oLogicDocument)
Expand Down Expand Up @@ -2463,10 +2448,21 @@ background-repeat: no-repeat;\
// пустой метод
};

asc_docs_api.prototype.asc_findText = function(text, isNext, isMatchCase)
asc_docs_api.prototype.asc_findText = function(text, isNext, isMatchCase, callback)
{
return this.WordControl.m_oLogicDocument.findText(text, isNext === true);
var SearchEngine = editor.WordControl.m_oLogicDocument.Search(text, {MatchCase : isMatchCase});

var Id = this.WordControl.m_oLogicDocument.GetSearchElementId(isNext);

if (null != Id)
this.WordControl.m_oLogicDocument.SelectSearchElement(Id);

var result = SearchEngine.Count;
if (callback)
callback(result);
return result;
};

// returns: CSearchResult
asc_docs_api.prototype.sync_SearchFoundCallback = function(obj)
{
Expand Down Expand Up @@ -8115,7 +8111,6 @@ background-repeat: no-repeat;\
asc_docs_api.prototype['goToNextSearchResult'] = asc_docs_api.prototype.goToNextSearchResult;
asc_docs_api.prototype['gotoSearchResultText'] = asc_docs_api.prototype.gotoSearchResultText;
asc_docs_api.prototype['stopSearchText'] = asc_docs_api.prototype.stopSearchText;
asc_docs_api.prototype['findText'] = asc_docs_api.prototype.findText;
asc_docs_api.prototype['asc_searchEnabled'] = asc_docs_api.prototype.asc_searchEnabled;
asc_docs_api.prototype['asc_findText'] = asc_docs_api.prototype.asc_findText;
asc_docs_api.prototype['asc_replaceText'] = asc_docs_api.prototype.asc_replaceText;
Expand Down
24 changes: 16 additions & 8 deletions word/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3123,22 +3123,30 @@ background-repeat: no-repeat;\
}
};

asc_docs_api.prototype.asc_findText = function(text, isNext, isMatchCase)
asc_docs_api.prototype.asc_findText = function(text, isNext, isMatchCase, callback)
{
var result = 0;
var isAsync = false;
if (null != this.WordControl.m_oDrawingDocument.m_oDocumentRenderer)
{
this.WordControl.m_oDrawingDocument.m_oDocumentRenderer.findText(text, isMatchCase, isNext);
return this.WordControl.m_oDrawingDocument.m_oDocumentRenderer.SearchResults.Count;
isAsync = (true === this.WordControl.m_oDrawingDocument.m_oDocumentRenderer.findText(text, isMatchCase, isNext, callback)) ? true : false;
result = this.WordControl.m_oDrawingDocument.m_oDocumentRenderer.SearchResults.Count;
}
else
{
var SearchEngine = editor.WordControl.m_oLogicDocument.Search(text, {MatchCase: isMatchCase});

var SearchEngine = editor.WordControl.m_oLogicDocument.Search(text, {MatchCase : isMatchCase});
var Id = this.WordControl.m_oLogicDocument.GetSearchElementId(isNext);

var Id = this.WordControl.m_oLogicDocument.GetSearchElementId(isNext);
if (null != Id)
this.WordControl.m_oLogicDocument.SelectSearchElement(Id);

if (null != Id)
this.WordControl.m_oLogicDocument.SelectSearchElement(Id);
result = SearchEngine.Count;
}

return SearchEngine.Count;
if (!isAsync && callback)
callback(result);
return result;
};

asc_docs_api.prototype.asc_replaceText = function(text, replaceWith, isReplaceAll, isMatchCase)
Expand Down

0 comments on commit 517774c

Please sign in to comment.