keep the current cursor's position after an Xml insert.

Post here questions and problems related to oXygen frameworks/document types.
sebastienlavandier
Posts: 124
Joined: Tue May 29, 2012 5:42 pm

keep the current cursor's position after an Xml insert.

Post by sebastienlavandier »

Hi,

In my application, I can add some swing object to an xml document by drag and drop, by using "AuthorDnDListener", and most specially the function "authorDrop" (which is called when dnd is terminated). In this function, I use the function "AuthorDocumentController.insertXMLFragmentSchemaAware(...)" for add my object to the xml document at the current position by using "editorAccess.getCaretOffset()". That works very well !
But after, when I want to save my object in the xml referencement part, I use again the function "AuthorDocumentController.insertXMLFragmentSchemaAware(...)" with the xml referencement part position. That works too ! But the cursor's position is changed to the screen.
How can I do to keep the position's cursor of the first insert ?
Do you have an idea ?
Thanks in advance.
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: keep the current cursor's position after an Xml insert.

Post by Radu »

Hi,

Probably before making the second insert you could keep the caret position in a variable and then restore it after the insertion like:

Code: Select all

    int caretOffset = authorAccess.getEditorAccess().getCaretOffset();
//Perform second operation and then:
authorAccess.getEditorAccess().setCaretPosition(caretOffset);
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sebastienlavandier
Posts: 124
Joined: Tue May 29, 2012 5:42 pm

Re: keep the current cursor's position after an Xml insert.

Post by sebastienlavandier »

Hi Radu,

I tried this, but after the second insert the value of the caret position become false (because an xml fragment was inserted).

I can't use this solution.
Do you have another ?
Thanks.
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: keep the current cursor's position after an Xml insert.

Post by Radu »

Hi Sebastien,

Using the Author API you can also create flexible positions (which are updated when the content changes). Something like this:

Code: Select all

Position position = authAccess.getDocumentController().createPositionInContent(authAccess.getEditorAccess().getCaretOffset());
//Perform operation here
authAccess.getEditorAccess().setCaretPosition(position.getOffset());
Maybe such a workaround will give you better flexibility.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sebastienlavandier
Posts: 124
Joined: Tue May 29, 2012 5:42 pm

Re: keep the current cursor's position after an Xml insert.

Post by sebastienlavandier »

Hi Radu,
Thanks for you answer.
Now the cursor is at the good position (first insert), but the scroll screen stay to the 2nd insert.

Do you have another idea ? or a solution for the scroll ?
Thanks in advance.
Radu
Posts: 9057
Joined: Fri Jul 09, 2004 5:18 pm

Re: keep the current cursor's position after an Xml insert.

Post by Radu »

Hi Sebastien,

Sorry for the delay.
We do not have specific API for scrolling (but maybe we could add some).
But you can use this method

Code: Select all

ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPageBase.getAuthorComponent()
to obtain the swing JPanel on which the Author page is rendered.
The parent of this panel should be a JScrollPane and theoretically you could use its methods to obtain the scroll bounds before the action is performed and to set the same scroll bounds after the action is performed.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
sebastienlavandier
Posts: 124
Joined: Tue May 29, 2012 5:42 pm

Re: keep the current cursor's position after an Xml insert.

Post by sebastienlavandier »

Sorry for the delay
Thank you very much for your help
Bye
mihaela
Posts: 490
Joined: Wed May 20, 2009 2:40 pm

Re: keep the current cursor's position after an Xml insert.

Post by mihaela »

Hi,

Oxygen 14.1 was release and it contains a new method in the API to make a specific area of the Author mode visible. The method you can use is:

Code: Select all


ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPageBase.scrollToRectangle(Rectangle) 
Here is the javadoc for this method:
http://www.oxygenxml.com/InstData/Edito ... Rectangle)

To get the rectangle corresponding to a specific offset you can use the following API:

Code: Select all


ro.sync.exml.workspace.api.editor.page.WSTextBasedEditorPage.modelToViewRectangle(int)
And the javadoc is:
http://www.oxygenxml.com/InstData/Edito ... angle(int)


Best Regards,
Mihaela
Mihaela Calotescu
http://www.oxygenxml.com
Post Reply