ONLYOFFICE / sdkjs-plugins

The add-ons for ONLYOFFICE Document Server and ONLYOFFICE Desktop Editors.
https://www.onlyoffice.com
Apache License 2.0
136 stars 134 forks source link

"SearchText" method doesn't work #159

Closed capricornstone closed 6 months ago

capricornstone commented 3 years ago

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?

ShockwaveNN commented 3 years ago

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

capricornstone commented 3 years ago

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);

ShockwaveNN commented 3 years ago

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

capricornstone commented 3 years ago

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

ShockwaveNN commented 3 years ago

Hm, have no idea

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

askonev commented 3 years ago

@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.

capricornstone commented 3 years ago

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 ?

askonev commented 3 years ago

@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.

capricornstone commented 3 years ago

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.

ShockwaveNN commented 3 years ago

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

image

capricornstone commented 3 years ago

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?

ShockwaveNN commented 3 years ago

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

askonev commented 2 years ago

@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

KirillovIlya commented 6 months ago

@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