Pointer Off Side When Inserting an Element
Having trouble installing Oxygen? Got a bug to report? Post it all here.
-
- Posts: 19
- Joined: Fri Dec 10, 2010 2:11 am
Pointer Off Side When Inserting an Element
Hi all,
I just created a java class, that can insert certain kinds of tags into a particular document type.
Now everything works perfectly except for when I insert this into a particular position. For example, the original xml file looks like:
<p><i> Text </i></p>
and I switch to the author mode, and I put my cursor after <P> but before <i> and insert the element. Ideally, the element inserted should reside between <p> and <i>, however, after insertion,the element will always be after the <i> instead of <p>.
This seems to be a small problem, but I've re-checked my Java class, and the only thing that may relate to this problem is the following code:
int caretPosition = authorAccess.getCaretOffset();
authorAccess.insertXMLFragment(mediaXML, caretPosition);
which looks correct to me.
So I would be grateful if anyone could help me debug. Thanks in advance!
I just created a java class, that can insert certain kinds of tags into a particular document type.
Now everything works perfectly except for when I insert this into a particular position. For example, the original xml file looks like:
<p><i> Text </i></p>
and I switch to the author mode, and I put my cursor after <P> but before <i> and insert the element. Ideally, the element inserted should reside between <p> and <i>, however, after insertion,the element will always be after the <i> instead of <p>.
This seems to be a small problem, but I've re-checked my Java class, and the only thing that may relate to this problem is the following code:
int caretPosition = authorAccess.getCaretOffset();
authorAccess.insertXMLFragment(mediaXML, caretPosition);
which looks correct to me.
So I would be grateful if anyone could help me debug. Thanks in advance!
-
- Posts: 9446
- Joined: Fri Jul 09, 2004 5:18 pm
Re: Pointer Off Side When Inserting an Element
Hi,
Probably the caret position is not between the <p> and the <i>.
For example in the Author page you can switch from the toolbar the Tags display to Full tags and see exactly where the caret is before invoking the operation.
You can also adjust the insert position a bit in this particular case like:
Regards,
Radu
Probably the caret position is not between the <p> and the <i>.
For example in the Author page you can switch from the toolbar the Tags display to Full tags and see exactly where the caret is before invoking the operation.
You can also adjust the insert position a bit in this particular case like:
Code: Select all
int caretPosition = authorAccess.getEditorAccess().getCaretOffset();
//Check if the caret position is right inside the <i> like:
//<p><i>{CARET}text</i></p>
//And adjust it if necessary
AuthorNode nodeAtOffset = authorAccess.getDocumentController().getNodeAtOffset(caretPosition);
if(nodeAtOffset.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
AuthorElement elemAtOffset = (AuthorElement) nodeAtOffset;
if(elemAtOffset.getName().equals("i")) {
//Inside an italic
if(elemAtOffset.getStartOffset() + 1 == caretPosition) {
//The case in which the caret position is right after the <i> tag.
AuthorNode parentOfI = authorAccess.getDocumentController().getNodeAtOffset(caretPosition - 1);
if(parentOfI.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
AuthorElement parentAtOffset = (AuthorElement) parentOfI;
if(parentAtOffset.getName().equals("p")) {
//We'll adjust the position where the insertion will take place
caretPosition --;
}
}
}
}
}
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
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