Spons
Spons

Reputation: 1591

CKEditor: Change Selection without losing it

i'm working with the CKEditor 4

The following is the case: I have a selection but i need to complete 2 actions. the first action is removing some span tags from the selection. the second action is wraping a span tag around the selection. The second action need to be done by the following action: editor.applyStyle(style);

The problem here is that the first action collapsed the selection and because it is collapsed it isn't usable for the second action.

Is there a javascript or Ckeditor related solution to maintain the selection?

I already tried maintaining it with Bookmarks and by change doing the second action first. But because the second action is working with spans it removes the other span tags. And i would like to have the control to say if a span tag will be deleted.

Upvotes: 0

Views: 901

Answers (1)

Reinmar
Reinmar

Reputation: 22023

In cases like yours CKEditor uses bookmarks, but you should know that there are few kinds of them - normal (based on node references), serializable (based on spans) and 3rd type (based on node addresses).

When DOM changes the most convenient ones are the serializable bookmarks, however, your code that "works with spans" need to be aware of them (they have special data-cke-bookmark attributes) and shouldn't remove them (but it can e.g. move them around).

There's no better way to remember a range if you're modifying DOM. Note that CKEditor's methods won't destroy your bookmarks unless you're removing e.g. entire bookmarks' ancestors.

Upvotes: 2

Related Questions