place cursor in text mode by API
Post here questions and problems related to oXygen frameworks/document types.
-
- Posts: 280
- Joined: Thu Nov 28, 2013 9:32 am
- Location: Hamburg/Germany
- Contact:
place cursor in text mode by API
Hi,
I am implementing a AuthorOperation which should jump to a specific element within an xml file that needs to be opened in text mode.
I already managed to open the file:
(and also to modify the content with editor.reloadContent()
But how can I place the cursor at a specific position? The target element even has an id attribute. So basically I want to trigger the behavior is if i'm clicking on a link "my-file.xml#my-id".
Thanks and regards,
Patrik
I am implementing a AuthorOperation which should jump to a specific element within an xml file that needs to be opened in text mode.
I already managed to open the file:
Code: Select all
PluginWorkspaceProvider.getPluginWorkspace().open(url, EditorPageConstants.PAGE_TEXT);
But how can I place the cursor at a specific position? The target element even has an id attribute. So basically I want to trigger the behavior is if i'm clicking on a link "my-file.xml#my-id".
Thanks and regards,
Patrik
-
- Posts: 9470
- Joined: Fri Jul 09, 2004 5:18 pm
Re: place cursor in text mode by API
Hi Patrik,
After the file is opened you can do something like:
Regards,
Radu
After the file is opened you can do something like:
Code: Select all
WSEditor editorAccess = PluginWorkspaceProvider.getPluginWorkspace().getEditorAccess(url, PluginWorkspace.MAIN_EDITING_AREA);
if(editorAccess != null){
WSEditorPage currentPage = editorAccess.getCurrentPage();
if(currentPage instanceof WSXMLTextEditorPage){
WSXMLTextEditorPage xmlTP = (WSXMLTextEditorPage) currentPage;
WSXMLTextNodeRange[] ranges = xmlTP.findElementsByXPath("//*[@id='myID']");
if(ranges != null && ranges.length > 0){
int startLine = ranges[0].getStartLine();
int startColumn = ranges[0].getStartColumn();
int offsetInDoc = xmlTP.getOffsetOfLineStart(startLine) + startColumn;
//This should place the caret immediately before the element.
xmlTP.setCaretPosition(offsetInDoc);
xmlTP.scrollCaretToVisible();
}
}
}
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 280
- Joined: Thu Nov 28, 2013 9:32 am
- Location: Hamburg/Germany
- Contact:
Re: place cursor in text mode by API
Thanks alot, Radu. This works fine - and knowing about the WSXMLTextNodeRange solves some other problems as well... :D
Regards,
Patrik
Regards,
Patrik
Return to “SDK-API, Frameworks - Document Types”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ 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