Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert text using tinyMCE into a paragraph block shows text but doesn't save it #12126

Closed
mtilly opened this issue Nov 20, 2018 · 7 comments
Closed
Labels
[Block] Classic Affects the Classic Editor Block [Feature] Extensibility The ability to extend blocks or the editing experience Needs Technical Feedback Needs testing from a developer perspective.

Comments

@mtilly
Copy link

mtilly commented Nov 20, 2018

Describe the bug
My plugin uses the command tinyMCE.execCommand("mceInsertContent", false, selection); to insert text from a metabox into a Gutenberg paragraph (or quoute) block. The text shows up at the cursor in the block, but when I save it (save draft or publish or update) or preview it, it is not shown. If I edit the block with HTML it is also gone.

If I insert the text and then follow it up with some manual typing, the text I inserted, along with what I type, is saved and shown on the preview.

For backward compatibility, shouldn't the tinyMCE insert command work on a gutenberg block? As identified in issue #4855 and #10509, the tinyMCE insert command does not insert at the cursor in a classic block. In this bug, it is inserting at the cursor in a Gutenberg block, but it isn't saving the text that is inserted.

To Reproduce
To reproduce you would need to use a JS call to tinyMCE.execCommand("mceInsertContent", false, selection); where selection is the text you want to insert. In my plugin this is called when they highlight a paragraph in a metabox (created by my plugin) and then click. This did seem to work in earlier versions of the beta until this weekend sometime.

Expected behavior
I would expect the text to be inserted at the cursor within the Para or Quote block and that the newly inserted text would be saved when I press save draft or publish or update, as well as show when previewed.

Desktop (please complete the following information):

  • OS: MAC OS Mojave 10.14.1
  • Browser Chrome
  • Version 70.0.3538.77

Additional context

  • Using Latest WordPress 5.0 beta available on 11/20/18
@designsimply designsimply added [External Package] TinyMCE [Feature] Extensibility The ability to extend blocks or the editing experience Needs Technical Feedback Needs testing from a developer perspective. labels Nov 20, 2018
@ellatrix ellatrix added [Block] Classic Affects the Classic Editor Block and removed [External Package] TinyMCE labels Nov 21, 2018
@mtilly
Copy link
Author

mtilly commented Nov 27, 2018

Another way around this would be if there is an equivalent to the "mceInsertContent" to be used with the new blocks. It would insert content at the current cursor position in the active block. Is there anything like this in the Gutenberg block interface?

@nicholasohrn
Copy link

If you're using send_to_editor, which obviously delegates to mceInsertContent, this occurs in the same manner. I have yet to find a workaround, unfortunately.

@youknowriad
Copy link
Contributor

TinyMCE is considered an implementation detail in Gutenberg and shouldn't be used as an API to insert content into Gutenberg blocks. We could in theory drop it from RichText. (In fact any imperative DOM API is not an official API)

Instead, I'd suggest using the format API to manipulate the content of RichText content.

We're still lacking documentation for this API but this plugin contains some good examples https://wordpress.org/plugins/advanced-rich-text-tools/

Thanks

@mtilly
Copy link
Author

mtilly commented Jan 4, 2019

Is there a place to look for API Documentation for Gutenberg - what is available and what may be coming? I'm afraid that trying to reverse engineer from the plugin is beyond me. Besides, without the doc I'm sure I could easily cause problems for other plugins/themes.

@youknowriad
Copy link
Contributor

The documentation lives here https://wordpress.org/gutenberg/handbook/

And you should look at the the issues labeled with "Documentation" to see what's coming.

@StephenAtty
Copy link

Although this has been closed for 2 years I think it's rather telling that the official documentation still doesn't give a solution.

Surely there has to be a simple way to insert "this is my new bit of text" into the block at the current cursor position.

@mike-solonevich
Copy link

Is there a solution yet? We really need a way to insert text to paragraph block via js and make it save it. Looks like it saves it when the block loses focus, but .trigger('focusout') doesn't help. Also, .click() or .focus() on another block doesn't place cursor there. The focus is still on the previous block. How to save the value of the paragraph, guys?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Classic Affects the Classic Editor Block [Feature] Extensibility The ability to extend blocks or the editing experience Needs Technical Feedback Needs testing from a developer perspective.
Projects
None yet
Development

No branches or pull requests

7 participants