When we press Enter in Author view
Are you missing a feature? Request its implementation here.
-
- Posts: 52
- Joined: Thu Dec 15, 2011 7:56 pm
When we press Enter in Author view
In the Author View.
When I press the Enter Key, a window appears and propose to me :
Our current element is a paragraph. When they hit the Enter key, my users would like this paragraph be splitted in 2 and then a new paragraph is automatically created (between the two <p> splitted) for the new text.
Is a such functionnality can be implemented ?
If yes, what are the java class to be used ?
Thank you for your help.
Vincent.
When I press the Enter Key, a window appears and propose to me :
- to split the current element.
- to insert other elements.
Our current element is a paragraph. When they hit the Enter key, my users would like this paragraph be splitted in 2 and then a new paragraph is automatically created (between the two <p> splitted) for the new text.
Is a such functionnality can be implemented ?
If yes, what are the java class to be used ?
Thank you for your help.
Vincent.
-
- Posts: 9436
- Joined: Fri Jul 09, 2004 5:18 pm
Re: When we press Enter in Author view
Hi Vincent,
The behavior your users want can still be done with the current behavior if the user first splits the paragraph and then splits again the second paragraph (basically if he presses ENTER four times).
I have not seen this behavior of creating three paragraphs when ENTER is pressed in any text processor but if they want this behavior:
You have the following two options:
1) You edit the document type and in the Actions list you add your own action with the keyboard shortcut ENTER and which triggers your own custom operation which will handle the split.
So when the user presses ENTER your Java operation will be invoked and it will be your responsibility to split the paragraph using the current API (probably creating a document fragment from the caret offset to the end of the paragrapf, removing the content and then inserting the created fragment after the paragraph).
Proposal (1) has as a drawback that the content completion window will not be shown at all by Oxygen when ENTER is pressed, if you want to show allowed child elements at that certain offset you will have to implement your own content proposals window.
2) The ro.sync.ecss.extensions.api.AuthorDocumentController has a method called: ro.sync.ecss.extensions.api.AuthorDocumentController.setDocumentFilter(AuthorDocumentFilter).
In the AuthorDocumentFilter you could overwrite this method:
and instead of delegating the default behavior you could also perform your own split using the API.
Or you could delegate to the default behavior twice, this could also work.
Based on your decision I can give you more implementation details for each approach.
Regards,
Radu
The behavior your users want can still be done with the current behavior if the user first splits the paragraph and then splits again the second paragraph (basically if he presses ENTER four times).
I have not seen this behavior of creating three paragraphs when ENTER is pressed in any text processor but if they want this behavior:
You have the following two options:
1) You edit the document type and in the Actions list you add your own action with the keyboard shortcut ENTER and which triggers your own custom operation which will handle the split.
So when the user presses ENTER your Java operation will be invoked and it will be your responsibility to split the paragraph using the current API (probably creating a document fragment from the caret offset to the end of the paragrapf, removing the content and then inserting the created fragment after the paragraph).
Proposal (1) has as a drawback that the content completion window will not be shown at all by Oxygen when ENTER is pressed, if you want to show allowed child elements at that certain offset you will have to implement your own content proposals window.
2) The ro.sync.ecss.extensions.api.AuthorDocumentController has a method called: ro.sync.ecss.extensions.api.AuthorDocumentController.setDocumentFilter(AuthorDocumentFilter).
In the AuthorDocumentFilter you could overwrite this method:
Code: Select all
public boolean split(AuthorDocumentFilterBypass filterBypass, AuthorNode toSplit, int splitOffset)
Or you could delegate to the default behavior twice, this could also work.
Based on your decision I can give you more implementation details for each approach.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 52
- Joined: Thu Dec 15, 2011 7:56 pm
Re: When we press Enter in Author view
Thank you Radu,
Both of your solutions are good for us. (My users are in search of a "Word like" editing mode, so they would prefer not to see the content completion)
I really appreciate your support.
Vincent.
Both of your solutions are good for us. (My users are in search of a "Word like" editing mode, so they would prefer not to see the content completion)
I really appreciate your support.
Vincent.
-
- Posts: 9436
- Joined: Fri Jul 09, 2004 5:18 pm
Re: When we press Enter in Author view
Hi Vincent,
So approach number (1):
Create your own Author operation Java implementation extending ro.sync.ecss.extensions.api.AuthorOperation.
The implementation code for such a Split operation could be something like this:
Regards,
Radu
So approach number (1):
Create your own Author operation Java implementation extending ro.sync.ecss.extensions.api.AuthorOperation.
The implementation code for such a Split operation could be something like this:
Code: Select all
/**
* @see ro.sync.ecss.extensions.api.AuthorOperation#doOperation(ro.sync.ecss.extensions.api.AuthorAccess, ro.sync.ecss.extensions.api.ArgumentsMap)
*/
@Override
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
throws IllegalArgumentException, AuthorOperationException {
//Split the current paragraph
int caretOffset = authorAccess.getEditorAccess().getCaretOffset();
AuthorNode paragraphAtCaret = null;
try {
//Maybe we are in an XML tag which is a child or descendant of a <p>
AuthorNode currentNode = authorAccess.getDocumentController().getNodeAtOffset(caretOffset);
while(currentNode != null) {
if("p".equals(currentNode.getName())) {
//Found it
paragraphAtCaret = currentNode;
break;
}
}
} catch (BadLocationException e) {
e.printStackTrace();
}
if(paragraphAtCaret != null) {
//The caret is inside a paragraph.
try {
AuthorDocumentFragment rightSplit = null;
if(caretOffset < paragraphAtCaret.getEndOffset()) {
rightSplit = authorAccess.getDocumentController().createDocumentFragment(caretOffset,
//The end offset is inclusive so the created fragment will actually be a <p> holding inside it the content
paragraphAtCaret.getEndOffset());
} else {
//ENTER WAS PRESSED AT THE END OF THE PARA
}
//The empty <p/>
String xmlToInsert = "<p/>";
if(rightSplit != null) {
//The right splitted <p>
xmlToInsert += authorAccess.getDocumentController().serializeFragmentToXML(rightSplit);
}
//Insert the new content
authorAccess.getDocumentController().insertXMLFragment(xmlToInsert, paragraphAtCaret.getEndOffset() + 1);
if(rightSplit != null) {
//Delete the old content
authorAccess.getDocumentController().delete(caretOffset, paragraphAtCaret.getEndOffset() - 1);
}
//Place the caret in the empty paragraph
authorAccess.getEditorAccess().setCaretPosition(paragraphAtCaret.getEndOffset() + 2);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
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)
- ↳ 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