Select multiple text strings in TinyMCE

TinyMCE has a menu option to find, search, and replace. I am looking for a way to do this within our application via JavaScript. I cannot find any way using the current documents to tell TinyMCE to search for all the instances of a string, then do some formatting to them. There is an option to select certain nodes. However, I have only been successful in selecting HTML tags. I wondered if I am missing something, or does TinyMCE not give access to this via your application? This screenshot shows how the editor menu can select multiple instances of a string and apply formatting to only that. That is what I want control over. Does anybody know how to do that? Thanks for any help

I am not sure what you are trying to achieve but if you want to search and replace words or phrases in your text, you can use getContent() to get the text, then use a String.replaceAll() in javascript and set back the changed text with setContent()

1 Like

Hi, and thanks for the reply. What you suggest is exactly what I had come up with. However, I thought I might be ignoring some of the power built into their construct called execCommand, etc.

tinymce.activeEditor.execCommand('mceReplaceContent', false, 'My replacement content');
tinymce.activeEditor.execCommand('mceSelectNode', false, '<DOM_node>');

After not finding a way I had success with this.

var editor = tinymce.get('mytextarea'); 
var content = editor.getContent();
content = content.replace(/Bears/g, 'Lions');

However, I did not want to miss a better way to use this. Also, they seem to do things in a way I have never seen before. I cannot make a browsers textarea select text like in the picture with a mouse or JavaScript. I see Google Chrome has an Extention to do it. I could put selecting text like that to good work for our application. After looking for how… it seems like something TinyMCE does not give access to outside of the editor.

Thank you for this. I was only used to replace. :smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.