Hello ![]()
How to insert a new tag around the selected text (if selection is not collapsed) without breaking the formatting?
For example, you write a rich text, then do a selection that spans into different tags, and you want to put a custom tag around that selection. Take this code as example, selection is in red:
<span>this is <b>my</b> example text</span>
inserting a custom mytag
<span>this</span><mytag> is <b>m</b></mytag><span><b>y</b> example text</span>
Which - I guess - is the regular way to tagging a selected text.
I tried to figure it out watching sources for the link plugin, which seems to use fake objects, but I can't understand how it does that ![]()
Can someone help me, please?
Thanks in advance
~Aki

Re: Tagging the selected text
Re: Tagging the selected text
Ok, thanks.
I've looked mostly at styles and format plugins, but I'm having some troubles when it comes to handling styles:
as I got it, when you have created a style object, you can use the methods CKEDITOR.style.prototype.apply and .remove. Apply will apply the style to the current selection, and this is fine, but remove's behavior confuse me a little: if I place the cursor on the style, and I remove it, it removes the style in the current element, but not it's siblings. For example:
applying a style that spans between the tags, I get - correctly:
But when it comes to remove the mytag, if I place the cursor on it, and call remove(), it removes only one of the two parts:
or
Which could be logic, as I didn't select the whole style, but it depends on how the editor handles the tag breaking, and I can't be sure if two sibling annotations can be considered as a single one.
For example, this could be avoided if the breaking was made like this
Anyway, how shall I proceed for the removal?

Shall I select all the adjacent <mytag> and remove them at once?
Or shall I use some sort of bookmarking (which I still don't know nothing about)?
Meanwhile, thanks alfonsoml for your help
~Aki
Re: Tagging the selected text
Ok, for me this is hard to explain without real code, but I don't have the time to test it and explain it correctly so please bear with me.
In the style definition you can add two functions named childRule and parentRule that can be used to check if an element must be splitted or not while applying it.
Look at this checking:
http://dev.ckeditor.com/changeset/5009
It would be very nice if you can write a short example to finally show how you made work all of this.
In fact, I've realized now that there's no docs about what can go in a Style definition, wow, that's a big oversight!
Re: Tagging the selected text
Ok, thanks. I'm trying to figure out how to use correctly these methods...
But, so far, I got that they are involved only in checking: for example, I can avoid that a <strong> tag is split by <mytag>, but can I change the way it's split?
Looking at styles/plugin.js source code, it seems that tags are processed in a linear fashion: if multiple tags are selected, process the first (leftmost) tag, then go right until you find the rightmost one currently selected.
But processing in another way, such as transforming
to
I think this involves a hierarchal splitting (starting from the smallest node, B, and going up until all the range is covered).
)
I'll continue to explore this way, but isn't there a faster way to annotate the whole style block to remove it at once?
Thanks for your precious help (and yes, I'll write down a tutorial or something ASAP I'm getting confident on this kind of code manipulations
~Aki
Re: Tagging the selected text
Re: Tagging the selected text
Now it's working pretty well, as the html parser is not much intrusive.
I'll write something about it and, if I've time, I'll try to do the same thing with ckeditor DOM's functions.
Thanks for the help so far
EDIT:
Anyway CKEditor bookmarking is useful, as it simplify working with DOM, as it puts a tag where a range usually works with offsets.
~Aki