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 » Mon Jun 18, 2012 10:38 am

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: 7094
Joined: Fri Jul 09, 2004 5:18 pm

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

Post by Radu » Mon Jun 18, 2012 12:24 pm

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 » Mon Jun 18, 2012 1:23 pm

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: 7094
Joined: Fri Jul 09, 2004 5:18 pm

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

Post by Radu » Mon Jun 18, 2012 2:05 pm

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 » Tue Jun 19, 2012 10:38 am

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: 7094
Joined: Fri Jul 09, 2004 5:18 pm

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

Post by Radu » Wed Jun 20, 2012 3:30 pm

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 » Fri Jul 13, 2012 11:39 am

Sorry for the delay
Thank you very much for your help
Bye

mihaela
Posts: 225
Joined: Wed May 20, 2009 2:40 pm

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

Post by mihaela » Wed Oct 24, 2012 9:26 am

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