Moving Cursor on Page change
Post here questions and problems related to oXygen frameworks/document types.
Moving Cursor on Page change
Hi,
I'm working on a plugin method that reads a Processing Instruction which is created when the user saves in the editor. The next time they open the document, I would like to have the cursor move to the start offset of the node where I find the PI. So far I can save the instruction just fine, but I cannot seem to find a way to move the cursor. I did see that there is a deprecated method using AuthorAccess and a MoveCaretOperation Interface, but I have not found a way to implement this behavior.
Is there a way to do this in a WorkspaceAccess plugin?
Thank you!
I'm working on a plugin method that reads a Processing Instruction which is created when the user saves in the editor. The next time they open the document, I would like to have the cursor move to the start offset of the node where I find the PI. So far I can save the instruction just fine, but I cannot seem to find a way to move the cursor. I did see that there is a deprecated method using AuthorAccess and a MoveCaretOperation Interface, but I have not found a way to implement this behavior.
Is there a way to do this in a WorkspaceAccess plugin?
Thank you!
-
- Posts: 406
- Joined: Mon May 09, 2016 9:37 am
Re: Moving Cursor on Page change
Post by sorin_carbunaru »
Hi,
Have you taken a look at ro.sync.exml.workspace.api.editor.page.WSTextBasedEditorPage.setCaretPosition(int)?
You can use it in a code similar to this one:
Best wishes,
Sorin Carbunaru
Oxygen XML Editor
Have you taken a look at ro.sync.exml.workspace.api.editor.page.WSTextBasedEditorPage.setCaretPosition(int)?
You can use it in a code similar to this one:
Code: Select all
WSEditor editor = PluginWorkspaceProvider.getPluginWorkspace()
.getCurrentEditorAccess(PluginWorkspace.MAIN_EDITING_AREA);
if (editor != null) {
WSEditorPage currentPage = editor.getCurrentPage();
if (currentPage instanceof WSTextBasedEditorPage) {
int position = computeCaretPosition();
((WSTextBasedEditorPage) currentPage).setCaretPosition(position);
}
}
Sorin Carbunaru
Oxygen XML Editor
Re: Moving Cursor on Page change
Thank you! I looked over using that, but that did work to get the position and attempt to set it.
The only issue is that on editorPageChanged I use the method like you provided and the caret jumps to where I wanted, but then immediately jumps back to the top of the document. Is there another event firing after the page change that would cause the cursor to be moved again?
The only issue is that on editorPageChanged I use the method like you provided and the caret jumps to where I wanted, but then immediately jumps back to the top of the document. Is there another event firing after the page change that would cause the cursor to be moved again?
Re: Moving Cursor on Page change
Hi,
From what I remember Oxygen should also try to restore the caret position to the last location where it was in the document when it was last closed.
Maybe you can use invoke later to post pone a bit setting the caret to the custom location where you want to set it:
Regards,
Radu
From what I remember Oxygen should also try to restore the caret position to the last location where it was in the document when it was last closed.
Maybe you can use invoke later to post pone a bit setting the caret to the custom location where you want to set it:
Code: Select all
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
((WSTextBasedEditorPage) currentPage).setCaretPosition(position);
}
});
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service