陈同学
陈同学

Reputation: 21

Tinymce: How to trigger autocomplete when I do execCommand('mceInsertContent', '#')

When I press the button do execCommand('mceInsertContent', '#') and insert # to the tinymce editor, but the autocompleter doesnt display.

The image: enter image description here

Upvotes: 2

Views: 315

Answers (2)

Maslow
Maslow

Reputation: 1104

Ok Since Tinymce 7 you can do that

editor.ui.registry.addButton("addMentionUser", {
  text: "User",
  onAction: () => {
    editor.insertContent("$");
    editor.execCommand("mceAutocompleterReload");
  },
});

Upvotes: 0

Maslow
Maslow

Reputation: 1104

Hey I managed to do it this way (tested with TinyMCE 6.7)

editor.ui.registry.addButton("addMentionUser", {
  text: "User",
  onAction: () => {
    editor.insertContent("$");
    editor.fire("keypress");
  },
});

Upvotes: 0

Related Questions