From d37824518afbb64320ed08afb984e207fab5b848 Mon Sep 17 00:00:00 2001 From: KirillovIlya Date: Mon, 19 Feb 2024 13:04:09 +0300 Subject: [PATCH] For bug #47709 Implement a new plugin method to find and select specified text --- word/api_plugins.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/word/api_plugins.js b/word/api_plugins.js index ffb1b09722..628ff56e39 100644 --- a/word/api_plugins.js +++ b/word/api_plugins.js @@ -474,6 +474,35 @@ this.WordControl.m_oLogicDocument.ReplaceSearchElement(sReplace, true, null, false); }; + /** + * Find and select the next occurrence of the text starting at the current position. + * @memberof Api + * @typeofeditors ["CDE"] + * @alias SearchAndReplace + * @param {Object} oProperties - An object which contains the search and replacement strings. + * @param {string} oProperties.searchString - The search string. + * @param {string} oProperties.replaceString - The replacement string. + * @param {boolean} [isForward=true] - Search direction. + * @returns {boolean} returns false if text was not found + */ + window["asc_docs_api"].prototype["pluginMethod_SearchNext"] = function(oProperties, isForward) + { + let logicDocument = this.WordControl.m_oLogicDocument; + if (!logicDocument) + return false; + + let searchProps = new AscCommon.CSearchSettings(); + searchProps.SetText(oProperties["searchString"]); + searchProps.SetMatchCase(undefined !== oProperties["matchCase"] ? oProperties["matchCase"] : true); + + logicDocument.Search(searchProps); + let elementId = logicDocument.GetSearchElementId(!(false === isForward || 0 === isForward)); + if (null === elementId) + return false; + + logicDocument.SelectSearchElement(elementId); + return true; + }; /** * Returns file content in the HTML format. * @memberof Api