sdkjs-plugins icon indicating copy to clipboard operation
sdkjs-plugins copied to clipboard

"SearchText" method doesn't work

Open capricornstone opened this issue 3 years ago • 13 comments

I find a plugin example "example_search_and_change_text_background_color",

there is a program statement is commented: window.Asc.plugin.executeMethod("SearchText",[text, true]);

I try to use the "SearchText" method but it doesn't work. Is there an example of such a plugin: when searching a word, the editor can automatically jump to the location of the word?

capricornstone avatar Jul 07 '21 01:07 capricornstone

Could you describe version of your produce

I checked plugin from this version

with DocumentServer v6.3.1 image

And it seems working

But generally speaking since this plugin is on sdkjs#develop it may or may not work in any situation

ShockwaveNN avatar Jul 07 '21 11:07 ShockwaveNN

version is 6.3.0.111,document.permissions.edit is false,Any search function is invalid,e.g window.Asc.plugin.callCommand(function() { Api.asc_findText(Asc.scope.text,true,true); }, false);

capricornstone avatar Aug 10 '21 01:08 capricornstone

Example I linked do not use asc_findText method, could you try similar as in example

And I may wrong - but I cannot find documentation for method asc_findText anywhere - maybe this method is deprecated, could you point out where did you find it

ShockwaveNN avatar Aug 10 '21 07:08 ShockwaveNN

https://github.com/ONLYOFFICE/sdkjs/blob/v6.3.0.111/word/api.js line 3018 when document.permissions.edit is true,method asc_findText is valid

capricornstone avatar Aug 10 '21 07:08 capricornstone

Hm, have no idea

@askonev please take a look, if this method is undocumented - is it allowed to be used?

ShockwaveNN avatar Aug 10 '21 07:08 ShockwaveNN

@capricornstone Hi! This method ("SearchText") is not fully implemented and because of this, it's not documented. We advise you not to use it.

Also, the asc_findText method is not intended to be used for the plugin to work. For those in your situation, the best way would be to use the macros script in the plugin or use and adapt the method searchandreplace.

askonev avatar Aug 10 '21 15:08 askonev

when DocumentServer's config : document.permissions.edit=false,the macros script in the plugin or the method searchandreplace doesn't seem to work, Is there any way to implement search method where DocumentServer's config:document.permissions.edit= false ?

capricornstone avatar Aug 11 '21 01:08 capricornstone

@capricornstone. The "document.permissions.edit = false" mode implies denial of access for the user both through the interface and through plugins.

Can you explain in more detail what you want to implement please.

askonev avatar Aug 13 '21 15:08 askonev

I want to achieve the following functions: Word documents are read-only and cannot be modified by users. There is an input text box and a search button outside the OnlyOffice editor. Users can enter text in the input box and click the search button. The OnlyOffice editor automatically searches for the text and locates the location of the text.

capricornstone avatar Aug 16 '21 02:08 capricornstone

@capricornstone Why this cannot be done by using default search window? It is not blocked in read-only mode

image

ShockwaveNN avatar Aug 16 '21 07:08 ShockwaveNN

In fact, I also need this function: there are some designated keywords behind the text input box outside the onlyoffice editor. Clicking on the keywords will locate the designated position in the Word document. Or, is there a way to open the default search window through a plug-in, and fill in the specified keywords in the text box of the default search window, and then search automatically?

capricornstone avatar Aug 16 '21 08:08 capricornstone

I don't think so, but maybe @askonev have something to say

ShockwaveNN avatar Aug 16 '21 08:08 ShockwaveNN

@capricornstone Hi! At the moment, it is not possible to use methods for the plugin in view mode. Wrote enhancement in our internal repository #55230

askonev avatar Jan 31 '22 14:01 askonev

@capricornstone Hello, thank you for your report In version 8.0.1 was added a new method for finding the next occurrence of text

window.Asc.plugin.executeMethod("SearchNext", [{
                    searchString: 'test',
                    matchCase: false,
                    isForward: false
                }],
                function (result) {
                    if (!result) {
                        console.log(`returns ${result} if text was not found`)
                    }
                }
            );

Also, in the next version 8.1.0 will be improved the check if builder script can be executed. As a result, any script that does not change the document can be executed in the view mode

KirillovIlya avatar Mar 07 '24 10:03 KirillovIlya