Prasad
Prasad

Reputation: 59491

Ckeditor issue with InsertText

I am trying to use the following command to insert a text to the CKEditor:

CKEDITOR.instances.Body.insertText('$${FIRSTNAME}');

The above command works fine when the cursor is at plain text. When i try to insert the text between a text which has attribute, it inserts on single $ instead of $$ of $${FIRSTNAME}. I have uploaded the sample to the jsbin to reproduce the issue

http://jsbin.com/ahikeh/1

Please suggest an alternative to fix this issue.

Upvotes: 0

Views: 1077

Answers (2)

Reinmar
Reinmar

Reputation: 22023

This is an ugly bug :D I debugged the code and find the reason:

https://github.com/ckeditor/ckeditor-dev/blob/master/core/editable.js#L1616

String#replace method treats $$ as one $ (https://developer.mozilla.org/en/docs/JavaScript/Reference/Global_Objects/String/replace), so the data should have been protected.

I'm afraid that there's no simple workaround right now since you cannot escape the data beforehand. Depending on context the replace method will or won't be used.

So the best option will be to use other template pattern - e.g. %%{foo} - it will work correctly. And when getting data from the editor you can replace %% with $$.

Ticket: http://dev.ckeditor.com/ticket/10367

Upvotes: 2

Eli
Eli

Reputation: 14827

Try using insertHtml() instead:

CKEDITOR.instances.Body.insertHtml('<b>$${FIRSTNAME}</b>');

Updated Demo

Upvotes: 1

Related Questions