XML Comment Feature

Are you missing a feature? Request it's implementation here.
kruncher
Posts: 26
Joined: Tue Mar 31, 2009 5:47 pm

XML Comment Feature

Post by kruncher » Thu Jun 11, 2009 1:22 am

Hi guys,

I use the (Ctrl+Shift+,) shortcut to comment out selected XML all of the time. However, often I am wanting to comment out XML which already contains comments. Naturally this causes problems because in XML it is not possible to nest comments.

I think that it would be fantastic if this automatic comment feature toggled between the following (where the inner comment is automatically escaped and un-escaped):

Code: Select all

<my-node>
<!-- A comment. -->
<another-node/>
</my-node>

<!--<my-node>
<!-/- A comment. -/->
<another-node/>
</my-node>-->
Just an idea,

Many thanks,
Lea Hayes

Radu
Posts: 7529
Joined: Fri Jul 09, 2004 5:18 pm

Re: XML Comment Feature

Post by Radu » Thu Jun 11, 2009 8:30 am

Hi Lea,

Indeed we know about this limitation when using the "Toggle Comments" operation and we'll probably try to fix it in a minor version of Oxygen 11.
Your suggested solution to escaping inner comments is indeed a good one and we'll probably use something very similar to what you proposed.

In the meantime, Oxygen offers support for creating your own custom actions and adding them to the contextual menu in the Text page so if you know Java you could implement your custom method to toggle comments.
For this you can read the Plugins section from
http://www.oxygenxml.com/developer.html

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

kruncher
Posts: 26
Joined: Tue Mar 31, 2009 5:47 pm

Re: XML Comment Feature

Post by kruncher » Fri Jun 12, 2009 2:42 am

Hi,

Thanks for the link, I will have a go at creating my own plug-in to achieve this until the feature is available in the <oxygen/> editor.

Cheers!
Lea Hayes

kruncher
Posts: 26
Joined: Tue Mar 31, 2009 5:47 pm

Re: XML Comment Feature

Post by kruncher » Fri Jun 12, 2009 4:11 am

I have created the plugin, and it appears to work fine. It is a selection type plugin which shows up in the context menu.

How can I assign a keyboard shortcut to this plugin?

Preferably (Ctrl+Shift+,) because this is what I am used to.

Thanks,
Lea Hayes

Radu
Posts: 7529
Joined: Fri Jul 09, 2004 5:18 pm

Re: XML Comment Feature

Post by Radu » Fri Jun 12, 2009 3:05 pm

Hi Lea,

Starting from Oxygen 10.3 (couple of weeks) you will have the ability to assign keyboard shortcuts to your custom plugin actions.
Here is the modification which you will have to perform to your plugin.xml file in order to assign shortcuts to the action:

Code: Select all


<extension type="selectionProcessor" 
class="your.package.ToggleComments" keyboardShortcut="ctrl shift COMMA"/>
In order to know what value to give to the keyboardShortcut attribute for a certain shortcut you can go to the Oxygen Preferences->Menu shortcut keys, press Edit for any shortcut and then get the string representation by pressing the desired shortcut.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

kruncher
Posts: 26
Joined: Tue Mar 31, 2009 5:47 pm

Re: XML Comment Feature

Post by kruncher » Fri Jun 12, 2009 3:47 pm

Excellent, I have adjusted the plugin XML file so that when I patch in a couple of weeks it is all up and running!

Here is the Java code of the plugin that I have created in case anyone else runs into this forum message:

Code: Select all

package custom.oxygen.plugin.comment;

import ro.sync.exml.plugin.selection.SelectionPluginContext;
import ro.sync.exml.plugin.selection.SelectionPluginExtension;
import ro.sync.exml.plugin.selection.SelectionPluginResult;
import ro.sync.exml.plugin.selection.SelectionPluginResultImpl;

public class ToggleCommentPluginExtension implements SelectionPluginExtension
{
public SelectionPluginResult process(SelectionPluginContext context)
{
if (context.getSelection().matches("\\s*\\<\\!-- (\\-?[^\\-])*--\\>\\s*"))
{
// Remove surrounding comment tags and un-escape any nested comments.
String removedComments = context.getSelection().replaceFirst("(\\s*)\\<\\!-- ((-?[^\\-])*) --\\>(\\s*)", "$1$2$4");
return new SelectionPluginResultImpl(removedComments.replaceAll("-\\\\-", "--"));
}
else
{
// Surround selection with comment tags and escape any nested comments.
return new SelectionPluginResultImpl("<!-- " + context.getSelection().replaceAll("--", "-\\\\-") + " -->");
}
}
}
Thanks Radu!
Lea Hayes

Radu
Posts: 7529
Joined: Fri Jul 09, 2004 5:18 pm

Re: XML Comment Feature

Post by Radu » Mon Jun 15, 2009 10:16 am

Hi Lea,

Thanks for the code tip :)
We'll try to improve the in-editor "Toggle Comments" to take into account already existing comments in time for Oxygen 10.3 probably using the same escaping \ between the illegal -- that you suggested.
If this gets implemented, this will also be available on other Oxygen file types like CSS, JavaScript, SQL which also present multi-line comments.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Drew
Posts: 6
Joined: Thu Oct 25, 2018 7:14 pm

Re: XML Comment Feature

Post by Drew » Mon Feb 01, 2021 11:09 pm

What ever happened with this request to be able to comment out XML content that includes some XML comments already?

___

On a related question: For some reason Toggle Comment is no longer enabled (menu Document > Edit > Toggle Comment or key Control+Shift_Comma). Dunno how that happened. How can I enable it again?

Radu
Posts: 7529
Joined: Fri Jul 09, 2004 5:18 pm

Re: XML Comment Feature

Post by Radu » Tue Feb 02, 2021 10:38 am

Hi,

This forum thread is from 11 years ago, maybe you could have considered creating a new forum post.
About this question:
What ever happened with this request to be able to comment out XML content that includes some XML comments already?
In what editing mode are you editing your XML content? Text or Author?
This works in the Text editing mode. I'm testing with Oxygen 23.0 but it's been working for quite a number of years. It does not work in the Author visual editing mode.

About your last question:
On a related question: For some reason Toggle Comment is no longer enabled (menu Document > Edit > Tog...
It should be enabled if you have previously selected some content in the XML document.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply