Page 1 of 1

Split_element function

Posted: Mon Oct 07, 2013 1:44 pm
by idak
Hi,
I use the split_element function in a paragraph but it does not work inside a bold or italics text:

Code: Select all


<p>text text text text text <i><b>text (caret position) text text</b><i> text text </p>
here is my java code:

Code: Select all


if ("p".equals(paragraphAtCaret.getName())
|| ("b".equals(paragraphAtCaret.getName()) && "p".equals(paragraphAtCaret.getParent().getName()))
|| ("i".equals(paragraphAtCaret.getName()) && "p".equals(paragraphAtCaret.getParent().getName()))
|| ("sup".equals(paragraphAtCaret.getName()) && "p".equals(paragraphAtCaret.getParent().getName()))) {

Object action = authorAccess.getEditorAccess().getActionsProvider()
.getAuthorCommonActions().get("XML_Refactoring/Split_element");
authorAccess.getEditorAccess().getActionsProvider().invokeAction(action);
}
Best Regards,
Idak,

Re: Split_element function

Posted: Mon Oct 07, 2013 2:35 pm
by alex_jitianu
Hello,

At first glance the problem seems to be related with the if statement. In the XML snapshot that you sent, the caret is in a b element from an i element. The if statement allows only the case when the b element is inside a p.

If the node at caret is b, i, sup you should look into the ancestors of the node at caret for a p element.

Best regards,
Alex

Re: Split_element function

Posted: Mon Oct 07, 2013 5:17 pm
by idak
Hello Alex,
I change the if predicate but when use the the split element inside bold or italic tag it does not split a paragraph tag:

before split :

Code: Select all


<p>text text text text <b>text (caret position) bold</b> text text text text </p>
After split:

Code: Select all


<p>text text text text <b>text (caret position)</b><b> bold</b> text text text text </p>
I want have this result:

Code: Select all


<p>text text text text <b>text (caret position)</b></p><p><b> bold</b> text text text text </p>
Thanks,

Re: Split_element function

Posted: Tue Oct 08, 2013 2:00 pm
by Radu
Hi,

The "Split" action you are using splits the current element located at the current position, the b element in your case. This is all it does, it is not equivalent to the Split action performed when you press ENTER in a paragraph.
But you have enough API to implement such an operation yourself:

http://www.oxygenxml.com/forum/post21668.html#p21668

Regards,
Radu