Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#34371 closed feature request (fixed)

Allow Filtering of TinyMCE charmap / Special Characters

Reported by: mrwweb's profile mrwweb Owned by:
Milestone: 4.6 Priority: normal
Severity: normal Version:
Component: TinyMCE Keywords:
Focuses: Cc:

Description

The special characters feature of TinyMCE is quite useful and the list of characters it provides are generally the most popular. However, there are times when characters that would be extremely useful to site editors are missing. I and others have specifically run into this when building sites that need characters common in Hawaiian. Other common symobls I could imagine sites needing:

  • Currencies on finance-related sites
  • Math symbols on academic and educational sites (fractions, advanced calculus)
  • Music symbols
  • More shapes. (I can't think of a site that would need this right now, but I bet it exists.)
  • Common English characters missing on international keyboards.

Use case examples that require removing/reordering characters:

  • Style guide does not allow certain characters.
  • Reordering symbols to move commonly-used ones first to increase ease of use.
  • Removing unnecessary symbols helps site editors use the ones they need faster.

It would be very useful at all the above times to allow the Character Map characters to be filtered, so developers can add or remove characters.

WordPress continues to grow in different sectors and different languages, so allowing the map to be filtered would be useful to many different site editors.

Change History (19)

#1 @mrwweb
9 years ago

For reference, the current list of characters comes from:
/wp-includes/js/tinymce/plugins/charmap/plugin.js

#2 @swissspidy
9 years ago

WordPress doesn't currently have Javascripts actions and filters (see #21170), plus this is a standard TinyMCE file AFAIK. Maybe the charmap can be overridden by using the tinymce global?

#3 @mrwweb
9 years ago

@swissspidy Yeah. The implementation details have me a little confused, I'll admit. I've searched at length and have never found anyone describing a JS way to modify the charmap, in WP or out.

Would this work?

  • WordPress creates its own charmap array in PHP. (Probably just based on the current charmap plugin one)
  • Adds filter for PHP array.
  • Takes that array and sticks it into /wp-includes/js/tinymce/plugins/charmap/plugin.js with wp_localize_script()

This is probably the equivalent to "hacking core" in TinyMCE, since it requires modification of what I assume is the stock TinyMCE plugin file, so I don't know the implications for that in terms of future updates to TinyMCE.

But having said all that, it really would be helpful in a whole bunch of situations I know and probably even more that I don't.

This ticket was mentioned in Slack in #core-i18n by mrwweb. View the logs.


9 years ago

This ticket was mentioned in Slack in #core-editor by mrwweb. View the logs.


9 years ago

#6 @mrwweb
9 years ago

Following the above slack chat, it was determined this requires an upstream pull request so that the TinyMCE plugin allows settings. Once that happens, this could be filtered via tiny_mce_before_init.

This ticket was mentioned in Slack in #core-editor by mrwweb. View the logs.


9 years ago

#8 @mrwweb
9 years ago

New relevant TinyMCE GitHub ticket: https://github.com/tinymce/tinymce/issues/2609

#9 follow-up: @mrwweb
9 years ago

There's been some [progress over on TinyMCE's end](https://github.com/tinymce/tinymce/issues/2609#issuecomment-170460791). It sounds good to me, but I'm not knowledgable enough to know if this will work.

So we started working on this by adding some config options to replace and append to the current set of characters. We will also add a new event that gets fired when a custom character is inserted so you can implement the recently used characters logic if you want to.

So this is something we can provide in the upcoming patch release since it doesn't break any existing logic. If we want a more advanced dialog then it would have to wait for a 4.x feature release and those typically include a bunch of features.

@azaozz?

#10 in reply to: ↑ 9 @azaozz
9 years ago

Replying to mrwweb:

There's been some progress over on TinyMCE's end.

There are two new settings and a new event for TinyMCE's Charmap plugin. See: https://github.com/tinymce/tinymce/commit/75d57ffeeb91dd3c5872603cfc6ee6fbfe41cf4e.

  • charmap overrides the default characters.
  • charmap_append appends more characters.
  • insertCustomChar is fired on inserting a character.

These will be available in WordPress 4.5. To use them you will need a WP plugin that sets these options for TinyMCE and passes the appropriate JS arrays. See the above changeset for the exact format.

Last edited 9 years ago by azaozz (previous) (diff)

#11 @azaozz
9 years ago

  • Milestone changed from Awaiting Review to 4.5

This ticket was mentioned in Slack in #core by chriscct7. View the logs.


9 years ago

#13 @chriscct7
9 years ago

@mrwweb @azaozz is committing TinyMCE 4.3.4 in soon. Did you want to working on a patch to work with what TinyMCE added this release (enhancement deadline closes Wednesday) or did you need more time?

Last edited 9 years ago by chriscct7 (previous) (diff)

#14 @chriscct7
9 years ago

If the character map is overridden, it might be prudent to ensure it doesn't break the word counting on the post editor screen.

#15 @mrwweb
9 years ago

I haven't done a ton of testing but my little proof-of-concept plugin that uses charmap_append does appear to work. I just tested and the word count was find for that. I haven't played with actually overwriting the charmap. And I wish there were a charmap_prepend but that would have to be added upstream.

This ticket was mentioned in Slack in #core by jorbin. View the logs.


9 years ago

#17 follow-up: @jorbin
9 years ago

  • Milestone changed from 4.5 to Future Release

There is no patch on this ticket and the beta 1 deadline for 4.5 is tomorrow, so punting.

#18 in reply to: ↑ 17 ; follow-up: @mrwweb
9 years ago

Replying to jorbin:

There is no patch on this ticket and the beta 1 deadline for 4.5 is tomorrow, so punting.

@azaozz should correct me if I'm wrong but I think this ticket was resolved by the update in TinyMCE version in 4.5. I don't know if that means this gets marked as fixed or closed, but at least in the nightlies, this feature is working.

#19 in reply to: ↑ 18 @azaozz
9 years ago

  • Milestone changed from Future Release to 4.6
  • Resolution set to fixed
  • Status changed from new to closed

Replying to mrwweb:

...at least in the nightlies, this feature is working.

Right, this was fixed with the TinyMCE update.

Note: See TracTickets for help on using tickets.