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

Show matched emoji name instead of an ID in emoji suggestion box #2656

Merged
merged 22 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
28e338e
Tests: added test case.
engineering-this Dec 6, 2018
4ed806d
Tests: added manual test.
engineering-this Dec 6, 2018
c63bb93
Tests: added manual test.
engineering-this Dec 6, 2018
b41e529
Emoji: autocomplete panel will show emoji name instead of emoji id.
engineering-this Dec 6, 2018
c411f0b
Tests: corrected tags.
engineering-this Dec 18, 2018
59b8046
Tests: added test cases for emoji names cache.
engineering-this Dec 18, 2018
1a10e1c
Cached emoji names. Renamed getEmojiName to getEncodedName.
engineering-this Dec 18, 2018
1bcf633
Tests: updated test steps, removed redundant editor name.
engineering-this Dec 18, 2018
07812c4
Tests: added manual test.
engineering-this Dec 18, 2018
4598af0
Moved emoji preview to span, added styles to display it correctly.
engineering-this Dec 18, 2018
4f29168
Tests: removed EmojiPanel button.
engineering-this Dec 19, 2018
3e40cf4
Tests: changed element.$.innerText to element.getTexT() in assertion.
engineering-this Dec 19, 2018
e15d209
Reworked getEncodedName to addEncodedName, now function only adds mis…
engineering-this Dec 19, 2018
9a2e4fe
Tests: corrected codestyle.
engineering-this Jan 10, 2019
3ef13cb
Updated tests.
jacekbogdanski Nov 14, 2019
a6fb8e8
Refactoring.
jacekbogdanski Nov 14, 2019
42d9604
Updated test to use name instead of ID.
jacekbogdanski Nov 14, 2019
93059e9
Updated emoji name.
jacekbogdanski Nov 15, 2019
8b80bf7
Updated test description to contain underscores.
jacekbogdanski Nov 15, 2019
fe47c28
Rewording.
jacekbogdanski Nov 19, 2019
4de9296
Improved tests.
jacekbogdanski Nov 19, 2019
dd62de8
Added changelog entry.
jacekbogdanski Nov 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

## CKEditor 4.14

New features:

* [#2583](https://github.com/ckeditor/ckeditor-dev/issues/2583): Changed [Emoji](https://ckeditor.com/cke4/addon/emoji) suggestion box to show matched emoji name instead of an ID.

## CKEditor 4.13.1

Fixed Issues:
Expand Down
13 changes: 11 additions & 2 deletions plugins/emoji/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,11 @@
return arrTools.reduce(
items,
function( acc, item ) {
addEncodedName( item );
return acc + emojiTpl.output( {
symbol: htmlEncode( item.symbol ),
id: htmlEncode( item.id ),
name: htmlEncode( item.id.replace( /::.*$/, ':' ).replace( /^:|:$/g, '' ).replace( /_/g, ' ' ) ),
name: item.name,
group: htmlEncode( item.group ),
keywords: htmlEncode( ( item.keywords || [] ).join( ',' ) )
} );
Expand Down Expand Up @@ -599,7 +600,7 @@
editor._.emoji.autocomplete = new CKEDITOR.plugins.autocomplete( editor, {
textTestCallback: getTextTestCallback(),
dataCallback: dataCallback,
itemTemplate: '<li data-id="{id}" class="cke_emoji-suggestion_item">{symbol} {id}</li>',
itemTemplate: '<li data-id="{id}" class="cke_emoji-suggestion_item"><span>{symbol}</span> {name}</li>',
outputTemplate: '{symbol}'
} );
}
Expand Down Expand Up @@ -641,6 +642,7 @@
return a.id > b.id ? 1 : -1;
}
} );
data = arrTools.map( data, addEncodedName );
callback( data );
}
} );
Expand All @@ -657,6 +659,13 @@

}
} );

function addEncodedName( item ) {
if ( !item.name ) {
item.name = htmlEncode( item.id.replace( /::.*$/, ':' ).replace( /^:|:$/g, '' ) );
}
return item;
}
} )();

/**
Expand Down
4 changes: 4 additions & 0 deletions plugins/emoji/skins/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
font-family: sans-serif, Arial, Verdana, "Trebuchet MS", "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

.cke_emoji-suggestion_item span {
font-family: "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}

.cke_emoji-panel {
width: 310px;
height: 300px;
Expand Down
29 changes: 28 additions & 1 deletion tests/plugins/emoji/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@
}
},

// This test should be on top of test suite, cause other tests will cache emojis (#2583).
'test emoji names cache': function( editor, bot ) {
bot.setHtmlWithSelection( '<p>foo :collision:^</p>' );

var collision = CKEDITOR.tools.array.filter( editor._.emoji.list, function( item ) {
return item.id === ':collision:';
} )[ 0 ];

assert.isUndefined( collision.name, 'Emoji name should be undefined.' );

editor.editable().fire( 'keyup', new CKEDITOR.dom.event( {} ) );

assert.areEqual( 'collision', collision.name, 'Emoji name should be cached.' );
},

'test emoji objects are added to editor': function( editor ) {
emojiTools.runAfterInstanceReady( editor, null, function( editor ) {
assert.isObject( editor._.emoji, 'Emoji variable doesn\' exists' );
Expand Down Expand Up @@ -210,7 +225,19 @@
} );

arrayAssert.itemsAreSame( expected, actual );
assert.areSame( '😻 :smiling_cat_face_with_heart-eyes:', autocomplete.view.element.getChild( 0 ).getText(), 'First element in view should start from "smiling".' );
assert.areSame( '<span>😻</span> smiling_cat_face_with_heart-eyes' , autocomplete.view.element.getChild( 0 ).getHtml(), 'First element in view should start from "smiling".' );
} );
},

// (#2583)
'test emoji autocomplete panel displays name': function( editor, bot ) {
emojiTools.runAfterInstanceReady( editor, bot, function( editor, bot ) {
bot.setHtmlWithSelection( '<p>:smiling_cat_face_with_heart-eyes:^</p>' );
editor.editable().fire( 'keyup', new CKEDITOR.dom.event( {} ) );

var element = CKEDITOR.document.findOne( '.cke_emoji-suggestion_item' );

assert.areEqual( element.getHtml(), '<span>😻</span> smiling_cat_face_with_heart-eyes' );
} );
}
};
Expand Down
16 changes: 16 additions & 0 deletions tests/plugins/emoji/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@
setUp: function() {
bender.tools.ignoreUnsupportedEnvironment( 'emoji' );
},

// This test should be on top of test suite, cause other tests will cache emojis (#2583).
'test emoji names cache': function() {
var bot = this.editorBot,
collision = CKEDITOR.tools.array.filter( bot.editor._.emoji.list, function( item ) {
return item.id === ':collision:';
} )[ 0 ];

assert.isUndefined( collision.name, 'Emoji name should be undefined.' );

bot.panel( 'EmojiPanel', function( panel ) {
panel.hide();
assert.areEqual( 'collision', collision.name, 'Emoji name should be cached.' );
} );
},

'test emoji dropdown has proper components': function() {
var bot = this.editorBot;

Expand Down
11 changes: 11 additions & 0 deletions tests/plugins/emoji/manual/emojimatchlabel.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<textarea id="editor" cols="10" rows="10">
<p></p>
</textarea>

<script>
bender.tools.ignoreUnsupportedEnvironment( 'emoji' );

CKEDITOR.replace( 'editor', {
removeButtons: 'EmojiPanel'
} );
</script>
15 changes: 15 additions & 0 deletions tests/plugins/emoji/manual/emojimatchlabel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@bender-tags: 4.14.0, feature, emoji, 2583
@bender-ckeditor-plugins: wysiwygarea, toolbar, emoji
@bender-ui: collapsed
@bender-include: ../_helpers/tools.js

1. Focus the editor.
1. Type `:smiling_face:`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
1. Type `:smiling_face:`
2. Type `:smiling_face:` in the editor's content.

Copy link
Member

Choose a reason for hiding this comment

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

It's rather obvious if in the previous step you are asked to focus the editor.


## Expected:

The emoji suggestion box appears with the match: `☺️ smiling_face`.

## Unexpected:

The emoji suggestion box appears with the match: `☺️ :smiling_face:`.
9 changes: 9 additions & 0 deletions tests/plugins/emoji/manual/font.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<textarea id="editor" cols="10" rows="10">
<p></p>
</textarea>

<script>
bender.tools.ignoreUnsupportedEnvironment( 'emoji' );

CKEDITOR.replace( 'editor' );
</script>
15 changes: 15 additions & 0 deletions tests/plugins/emoji/manual/font.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@bender-tags: 4.14.0, feature, emoji, 2583
@bender-ckeditor-plugins: wysiwygarea, toolbar, emoji
@bender-ui: collapsed
@bender-include: ../_helpers/tools.js

1. Focus the editor.
1. Type `:smiling_face:`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
1. Type `:smiling_face:`
2. Type `:smiling_face:` in the editor's content.

Copy link
Member

Choose a reason for hiding this comment

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


## Expected:

Emoji suggestion box displays a nicely colored emoji symbol like this one: <span style="font-family:&quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;;">☺</span>.

## Unexpected:

Emoji suggestion box displays an ugly black and white smiley like this one: <span style="font-family:sans-serif">☺</span>