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

call to callCommand with different selections #174

Closed lorenzoale closed 8 months ago

lorenzoale commented 2 years ago

Do you want to request a feature or report a bug?

What is the current behavior? I need to get the content of a given control content with a given tag, let's say tag={content}. To do this I just remove all other elements from the document, but first I copy the content control. Then, after removing all elements I insert the control content.  The problem:

  1. is that when there is an image inside this content control, and the image is selected (because it was the last action that the user did), it just removes everything. 

  2. In a similar way, if the user selected some content control, it does not remove anything.

To avoid this I just moved the cursor by means of the plugin method, but I wonder is this could not be solved other way. 

window.Asc.plugin.executeMethod("MoveCursorToEnd",
        [true],
        function(){
                window.Asc.plugin.callCommand(
                    function() {
                        var oDocument = Api.GetDocument();
                        var contenu_CC=null;
                        var aContentControls = oDocument.GetAllContentControls();
                        for (var i = 0; i < aContentControls.length; i++) {
                            var tagName=aContentControls[i].GetTag();
                            if (tagName== "{content}"){
                                contenu_CC=aContentControls[i];
                            }
                        }
                        oDocument.RemoveAllElements();
                        oDocument.InsertContent([contenu_CC]);
                    },
                    false,
                    true,
                    function(){
                        window.parent.Common.Gateway.sendInfo (
                            {
                                request: curr_request,
                                args : { only_content: true }
                            }
                        );
                    }
                );
            }
        );

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

What is the expected behavior?

Which versions of sdkjs-plugins, and which browser / OS are affected by this issue? Did this work in previous versions of sdkjs-plugins? 7.1.1

askonev commented 2 years ago

@lorenzoale Hi! Yes, at the moment there is a technical limitation that you cannot change the content control while it is selected.

  1. is that when there is an image inside this content control, and the image is selected (because it was the last action that the user did), it just removes everything.

I could not reproduce this problem. Can you send a test example of the document and the plugin on which this scenario is reproduced?

  1. ...but I wonder is this could not be solved other way.

I think at the moment your solution is the best, if you want to implement in the body of the builder code first remove all elements, save one in memory and then put it back into the document.

lorenzoale commented 2 years ago

@askonev Hello, thanks for your answer. As for the reproducing the problem, it is ok if you say it is not possible to work with content control while is selected I can add the extra moveCursortoend and that's all. Thanks. However, in case you want to reproduce it anyway: Attached there is an example of a document with several content controls. The idea is to press an external button that will leave only the conent of 1 content control (the one with tag {conent}) and remove all the rest. This is what I'm doing in the following piece of code:

window.Asc.plugin.executeMethod("MoveCursorToEnd",
        [true],
        function(){
                window.Asc.plugin.callCommand(
                    function() {
                        var oDocument = Api.GetDocument();
                        var contenu_CC=null;
                        var aContentControls = oDocument.GetAllContentControls();
                        for (var i = 0; i < aContentControls.length; i++) {
                            var tagName=aContentControls[i].GetTag();
                            if (tagName== "{content}"){
                                contenu_CC=aContentControls[i];
                            }
                        }
                        oDocument.RemoveAllElements();
                        oDocument.InsertContent([contenu_CC]);
                    },
                    false,
                    true,
                    function(){
                    }
                );
            }
        );

However I had to add call to the method MoveCursorToEnd because if the image in the conent control was selected before calling to this piece of code, everything is removed.

EnteteDocV2 (1).docx

Thanks,

Alejandra.

askonev commented 2 years ago

@lorenzoale I'm sorry, but your request is very hard to read and it take a lot of time to understand tham, please provide more readable piceces of code and more detailed description. I have not enought free time to help you if I need to format your code and dig in that myself

lorenzoale commented 2 years ago

@askonev I'm really sorry for the inconvenients. You do not need to test, I got the idea and I know how to overcome my problem. I edited the previous comment and tried to make it clearer anyway. Thanks again for your help.

Rita-Bubnova commented 8 months ago

I close this issue. Feel free to comment or reopen it if you got further questions.