Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call to callCommand with different selections #174

Closed
lorenzoale opened this issue Sep 12, 2022 · 5 comments
Closed

call to callCommand with different selections #174

lorenzoale opened this issue Sep 12, 2022 · 5 comments
Assignees
Labels
waiting feedback Issues that we waiting to be answered from author of issue

Comments

@lorenzoale
Copy link

lorenzoale commented Sep 12, 2022

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
Copy link
Member

askonev commented Sep 12, 2022

@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
Copy link
Author

lorenzoale commented Sep 13, 2022

@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
Copy link
Member

askonev commented Sep 13, 2022

@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
Copy link
Author

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

@ShockwaveNN ShockwaveNN added the waiting feedback Issues that we waiting to be answered from author of issue label Sep 14, 2022
@Rita-Bubnova
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting feedback Issues that we waiting to be answered from author of issue
Projects
None yet
Development

No branches or pull requests

4 participants