How to programatically select all text inside a TinyMCE editor
Asked Answered
P

2

10

I'm looking for a way to programatically select all the content inside a TinyMCE editor instance.

The reason I need this is that I'd like it if all the text inside the editor was selected, as soon as someone clicks on it (I'm using TinyMCE in conjunction with JEditable, by the way).

Thanks,
Edan

Petula answered 27/4, 2010 at 16:44 Comment(0)
T
13

Assuming you have your TinyMCE editor instance stored in a variable called ed:

ed.selection.select(ed.getBody(), true);
Toothpick answered 27/4, 2010 at 17:12 Comment(2)
Thanks! I ended up adding a setup function in the tineMCE.init() settings, which did exactly this.Petula
@Tim Down what does ed stand for ?? how should i initializeCorking
D
1

For tinyMCE 4 I'm using the Range Object for selection:

function selectAll(editor) {
    range = editor.dom.createRng();
    range.selectNodeContents(editor.getBody());
    editor.selection.setRng(range);
}

selectAll(tinyMCE.focusedEditor);
Denominationalism answered 29/8, 2014 at 9:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.