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

Asynchronous load of emoji list #2049

Merged
merged 17 commits into from
Jun 21, 2018
Merged

Asynchronous load of emoji list #2049

merged 17 commits into from
Jun 21, 2018

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Jun 4, 2018

What is the purpose of this pull request?

New feature

Does your PR contain necessary tests?

All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

  • provide asynchronous load of emojis
  • provide configuration option to load custom emoji list

Close #2036

@@ -158,3 +174,34 @@
* @cfg {Number} [emoji_minChars = 2]
* @member CKEDITOR.config
*/

/**
* Address to json file containing emoji list. File is downloaded through {@link CKEDITOR.ajax#load} method
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON is an acronym should be uppercased.

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. There isn't any error handling. When emojis fail to load, then editor will throw new error for every try to insert emoji. In case of failing to load emojis file, plugin should shutdown gracefully.

  2. Listening to instanceReady event to bind all listeners fails when editor is ready before emojis are loaded (e.g. super lag on server-side). If editor is already ready, just create emoji autocomplete and init it.

  3. There is also very weird bug connected with undo

    1. Open emoji sample.
    2. Click into the editor.

    Expected result:

    Nothing happens.

    Actual result:

    Wild undo step appears. After applying it, preinserted emoji is changed back into text.

    What's even weirder, clicking inside the editor after undoing causes redo step to disappear…


/**
* Address to json file containing emoji list. File is downloaded through {@link CKEDITOR.ajax#load} method
* and url address is processed by {@link CKEDITOR#getUrl}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL is also an acronym ;)

@msamsel msamsel force-pushed the t/2036 branch 2 times, most recently from 25e5355 to 781de6d Compare June 18, 2018 08:58
@msamsel
Copy link
Contributor Author

msamsel commented Jun 18, 2018

I've rebase branch to contain change introduced in #2032

@msamsel msamsel requested a review from Comandeer June 18, 2018 09:10
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no tests for case when editor is loaded faster than file with emojis. There is also no test for failed loading of emojis.

I'm also not sure about current undo integration. If there's a situation when user already started typing and then emojis are loaded, selection jumps to the beginning of the editor and emoji substitution is recorded as extra undo step.

@mlewand
Copy link
Contributor

mlewand commented Jun 19, 2018

Issue reported by @Comandeer is valid. What's more imagine a case when CKEditor makes few snapshots before the :emoji_tokens: are replaced. That would mean that we'd have to change an entire snapshots history.

Instead let's make a tough decision and drop the feature which replaced valid emoji tokens in the content, at paste, drop, etc.

Ideally I'd like to keep this feature at paste event, however looking at the implementation, it's implemented using core text filter mechanics and it would require some refactoring to make it happen. We want to conclude it so instead we'll remove the feature of replacing text tokens with emoji entirely.

To sum it up:

  • Keep the async emoji loading
  • Remove parts of emoji that are replacing text tokens with real emojis on setData/insertText/paste/drop etc.

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

http://tests.ckeditor.test:1030/tests/plugins/emoji/customemojilist#tests%2Fplugins%2Femoji%2Fcustomemojilist%20test%20long%20ajax%20loading fails in IE9.

There are also some issues with support for particular emojis in IEs. Forcing OS emoji font (Segoe UI Emoji) should be a proper fix for this. However I'm not sure if it's present on systems older than Windows 10.

The other issue is support for Linux as this system AFAIR does not have any built-in font with emoji support.


if ( !match ) {
return null;
if ( editor.status !== 'ready' ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this if needed now, when substitution is removed and initialisation just creates autocomplete instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's required because of this bug: #2114

Inlining this function cause random error, where plugin might be not initialised during loading stage (depend how fast json will be loaded). Error was clearly visible in Firefox browser.

return elementsPath.contains( forbiddenScope ) ? false : true;
} else {
return true;
function initPlugin() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove the if mentioned above, then this function could be inlined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related to previous comment :)

},

// #2036
'test custom emoji list is loadd': function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: loadd → load

'test invalid emoji list': function() {
var editor = this.editors.classic2;
emojiTools.runAfterInstanceReady( editor, null, function( editor ) {
assert.isUndefined( editor._.emoji, 'There are created emoji private data, so emoji was loaded what is wrong for this case.' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem like good assertion message.

…ading to support emoji in IE, correct test to run on supported environments only.
@msamsel
Copy link
Contributor Author

msamsel commented Jun 20, 2018

Font injection for IE browser in divarea editor is extracted here: #2121

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When running tests/plugins/emoji/basic there are several errors in the console:

plugin.js:689 Uncaught TypeError: Cannot read property 'getClientRects' of undefined
    at View.getViewPosition (plugin.js:689)
    at View.updatePosition (plugin.js:910)
    at Autocomplete.onChange (plugin.js:418)
    at Autocomplete.<anonymous> (plugin.js:267)
    at CKEDITOR.dom.window.listenerFirer (event.js:144)
    at CKEDITOR.dom.window.CKEDITOR.event.fire (event.js:290)
    at domobject.js:46

I also slightly updated sample (Firefox had some styling issues) and fixed typo in tests, which disabled ignoring.

@msamsel
Copy link
Contributor Author

msamsel commented Jun 21, 2018

I correct those tests. :)

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated API docs, LGTM now!

@Comandeer Comandeer merged commit a299443 into t/1746 Jun 21, 2018
@Comandeer Comandeer deleted the t/2036 branch June 21, 2018 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants