Author actions when cursor is in a comment

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
whyme
Posts: 85
Joined: Fri Mar 08, 2013 8:58 am

Author actions when cursor is in a comment

Post by whyme » Mon Sep 20, 2021 7:50 pm

Hi,

I've tried a simple Author MoveCaretOperation to move the cursor to ancestor-or-self::*[1]. It works fine, except when the cursor is currently in a comment or processing instruction. In those cases the action does not start. I've found some other author actions that seem not to respond when the cursor is in a comment or processing instruction. Is this a feature or a bug? Are there workarounds? (I had hoped a simple MoveCaretOperation would be provide that workaround.)

adrian_sorop
Posts: 28
Joined: Wed Jun 22, 2016 2:48 pm

Re: Author actions when cursor is in a comment

Post by adrian_sorop » Tue Sep 21, 2021 11:29 am

Hi!

Try to use node():

Code: Select all

ancestor-or-self::node()[1]
* matches only element nodes.
node() matches comments, processing instructions and text nodes.

Hope it helps,
Adrian S.
Adrian Sorop
<oXygen/> XML Editor
http://www.oxygenxml.com

adrian_sorop
Posts: 28
Joined: Wed Jun 22, 2016 2:48 pm

Re: Author actions when cursor is in a comment

Post by adrian_sorop » Wed Sep 22, 2021 10:38 am

Hi again.

Now I sow that you had other issue:
It works fine, except when the cursor is currently in a comment or processing instruction. In those cases the action does not start.
I suppose the action it's not enabled for processing intructions.

The simplest way is to force the action be te enabled all the time: go to action's dialog box and set operation's Activation Xpath to "true()".

Regards,
Adrian S
Adrian Sorop
<oXygen/> XML Editor
http://www.oxygenxml.com

whyme
Posts: 85
Joined: Fri Mar 08, 2013 8:58 am

Re: Author actions when cursor is in a comment

Post by whyme » Tue Sep 28, 2021 7:51 pm

Hm, this is strange.

In a dummy project file, I have my cursor in a comment, XPath /root/a/b/comment(). I have a simple author action, to move to the current parent. I've adopted your suggested ancestor-or-self::node()[1] (though I'm not sure why I need to make this change -- ancestor-or-self::*[1] works fine in the Oxygen XPath/XQuery Builder when the context is a comment). I've added the XPath activation true(). (That feels like a hack -- shouldn't a blank value allow the action to be applicable whenever, wherever?)

Those settings finally get a response, but it selects the root element, not the parent! Same thing happens when [last()] is substituted for [1]. When the cursor is in an element or text node the behavior is as expected.

adrian_sorop
Posts: 28
Joined: Wed Jun 22, 2016 2:48 pm

Re: Author actions when cursor is in a comment

Post by adrian_sorop » Wed Sep 29, 2021 3:07 pm

So,
I've adopted your suggested ancestor-or-self::node()[1] (though I'm not sure why I need to make this change -- ancestor-or-self::*[1] works fine in the Oxygen XPath/XQuery Builder[...]
The MoveCaretOperation uses the following API ro.sync.ecss.extensions.api.AuthorDocumentController.findNodesByXPath(String, boolean, boolean, boolean) to detect the nodes from the xpath.

Code: Select all

/**
 *Finds the author nodes selected by the given XPath 2.0 expression.
 *
 * @param xpathExpression The XPath expression. If the XPath expression is relative, it will be computed in the context of the current caret position.
   * @param ignoreTexts If <code>true</code> Author text nodes will not be returned.
   * @param ignoreCData If <code>true</code> Author CDATA sections will not be returned.
   * @param ignoreComments If <code>true</code> Author comments will not be returned.
*/
AuthorNode[] findNodesByXPath(String xpathExpression, boolean ignoreTexts, boolean ignoreCData, boolean ignoreComments) 
In the code of the operation, this metod si called with all the boolean parameters on true. This means that comments, text nodes and CData are ignored.
I've logged an issue to reconsider this behaviour
I've added the XPath activation true(). (That feels like a hack -- shouldn't a blank value allow the action to be applicable whenever, wherever?)
The Activation XPath is documented as
An XPath 2.0 expression that applies to elements and attributes.
. This means that it takes into account elements only.
The XPath expression equivalent of the empty field is:

Code: Select all

boolean(self::*)
.
If you want, you can change the Activation XPath to something like

Code: Select all

boolean(self::node())
but I don't like, that's why I recommanded the true() funtion. The result should be the same.
Same thing happens when [last()] is substituted for [1]. When the cursor is in an element or text node the behavior is as expected.
I don't think I fully understand this case. Perhaps a small example would be usefull.
Anyways, as far as I understood, I think that ancestor axe should not be used with last(). You can try something like self::node()[last()]
Adrian Sorop
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply