Cursor position after xinclude insertion

Are you missing a feature? Request it's implementation here.
kim
Posts: 8
Joined: Fri Sep 09, 2016 9:38 pm

Cursor position after xinclude insertion

Post by kim » Wed Apr 03, 2019 9:58 pm

When inserting an xinclude, please consider having the cursor after be placed after the closing element (</xi:include>). Thanks!

sorin_carbunaru
Site Admin
Posts: 228
Joined: Mon May 09, 2016 9:37 am

Re: Cursor position after xinclude insertion

Post by sorin_carbunaru » Thu Apr 04, 2019 1:41 pm

Hi Kim,

How do you insert the "xi:include"? From the toolbar action?

And why do you want the cursor to be at the end? Is it to be able to insert one "xi:include" after the other?

One reason for having the cursor inside the element is to easily insert an "xi:fallback", which provides a mechanism for recovering from missing resources.

Best wishes,
Sorin Carbunaru
oXygen xML

kim
Posts: 8
Joined: Fri Sep 09, 2016 9:38 pm

Re: Cursor position after xinclude insertion

Post by kim » Thu May 09, 2019 9:45 pm

Hi, Sorin.

Apologies for the long delay in my response!

We have a customized menu option to insert xincludes (which inserts the fallback, too). No, it is not able to insert one after another until you move the cursor outside the closing xinclude tag.

We'd like the cursor to be at the end so that we could either insert multiple xincludes in a row or keep tying without having to manually click to place the cursor outside the closing tag.

I do appreciate the 'adding a fallback' use case, but perhaps, since we include a fallback when we insert the xinclude, this is something that we could configure?

Best,
Kim

sorin_carbunaru
Site Admin
Posts: 228
Joined: Mon May 09, 2016 9:37 am

Re: Cursor position after xinclude insertion

Post by sorin_carbunaru » Tue May 14, 2019 3:15 pm

Hello Kim,

What you can do is to create a new Author action in your framework over ExecuteMultipleActionsOperation (see https://www.oxygenxml.com/doc/versions/ ... ialog.html and https://www.oxygenxml.com/InstData/Edit ... ation.html), action which first calls your custom xi:include-inserting action and then invokes another Author action that moves the caret after the inserted xi:include element. For the second framework action, you could use for example JSOperation (see https://www.oxygenxml.com/InstData/Edit ... ation.html). The script would be something like this:

Code: Select all

function doOperation() {
    var caretOffset = authorAccess.getEditorAccess().getCaretOffset();
    var currentNode = authorAccess.getDocumentController().getNodeAtOffset(caretOffset);
    
	// Find the xi:include element, starting from the cursor position, by going up in the ancestors hierarchy
    var xiincludeNode = null;
    while (currentNode != null) {
        if ("xi:include".equals(currentNode.getName()) && "http://www.w3.org/2001/XInclude".equals(currentNode.getNamespace())) {
            xiincludeNode = currentNode;
            break;
        }      
        currentNode = currentNode.getParent();
    }
    
    if (xiincludeNode != null) {
		// Move after the xi:include element
        authorAccess.getEditorAccess().setCaretPosition(xiincludeNode.getEndOffset() + 1);
    }  
}
Best wishes,
Sorin C.

kim
Posts: 8
Joined: Fri Sep 09, 2016 9:38 pm

Re: Cursor position after xinclude insertion

Post by kim » Tue May 14, 2019 4:16 pm

Thanks, Sorin! I'll give it a shot!

Post Reply