Browse Source

Rename shortnameToUnicode to shortnameToUtf8

Danilo Bargen 5 years ago
parent
commit
63b2e87914
3 changed files with 9 additions and 10 deletions
  1. 2 2
      src/directives/compose_area.ts
  2. 1 2
      src/helpers/emoji.ts
  3. 6 6
      tests/ts/emoji_helpers.ts

+ 2 - 2
src/directives/compose_area.ts

@@ -18,7 +18,7 @@
 import {ComposeArea} from '@threema/compose-area';
 import {ComposeArea} from '@threema/compose-area';
 
 
 import {isActionTrigger} from '../helpers';
 import {isActionTrigger} from '../helpers';
-import {parseEmoji, shortnameToUnicode} from '../helpers/emoji';
+import {parseEmoji, shortnameToUtf8} from '../helpers/emoji';
 import {BrowserService} from '../services/browser';
 import {BrowserService} from '../services/browser';
 import {LogService} from '../services/log';
 import {LogService} from '../services/log';
 import {ReceiverService} from '../services/receiver';
 import {ReceiverService} from '../services/receiver';
@@ -613,7 +613,7 @@ export default [
                     if (after.length === 0 && before.length > 2) {
                     if (after.length === 0 && before.length > 2) {
                         if (before.startsWith(trigger) && before.endsWith(trigger)) {
                         if (before.startsWith(trigger) && before.endsWith(trigger)) {
                             const trimmed = before.substr(1, before.length - 2);
                             const trimmed = before.substr(1, before.length - 2);
-                            const unicodeEmoji = shortnameToUnicode(trimmed);
+                            const unicodeEmoji = shortnameToUtf8(trimmed);
                             if (unicodeEmoji !== null) {
                             if (unicodeEmoji !== null) {
                                 composeArea.select_word_at_caret();
                                 composeArea.select_word_at_caret();
                                 composeArea.store_selection_range();
                                 composeArea.store_selection_range();

+ 1 - 2
src/helpers/emoji.ts

@@ -3105,7 +3105,6 @@ export function parseEmoji(text: string): Array<threema.EmojiInfo | string> {
     const result = [];
     const result = [];
 
 
     const textVariantSelector = '\ufe0e';
     const textVariantSelector = '\ufe0e';
-    const emojiVariantSelector = '\ufe0f';
 
 
     let match: string[];
     let match: string[];
     let startIndex: number = 0;
     let startIndex: number = 0;
@@ -3162,7 +3161,7 @@ export function parseEmoji(text: string): Array<threema.EmojiInfo | string> {
 /**
 /**
  * Translate a shortname to UTF8.
  * Translate a shortname to UTF8.
  */
  */
-export function shortnameToUnicode(shortname: string): string | null {
+export function shortnameToUtf8(shortname: string): string | null {
     return SHORTNAMES[shortname] || null;
     return SHORTNAMES[shortname] || null;
 }
 }
 
 

+ 6 - 6
tests/ts/emoji_helpers.ts

@@ -18,7 +18,7 @@
  */
  */
 
 
 import twemoji from 'twemoji';
 import twemoji from 'twemoji';
-import {emojify, enlargeSingleEmoji, parseEmoji, shortnameToUnicode} from '../../src/helpers/emoji';
+import {emojify, enlargeSingleEmoji, parseEmoji, shortnameToUtf8} from '../../src/helpers/emoji';
 
 
 
 
 const textVariantSelector = '\ufe0e';
 const textVariantSelector = '\ufe0e';
@@ -120,18 +120,18 @@ describe('Emoji Helpers', () => {
         });
         });
     });
     });
 
 
-    describe('shortnameToUnicode', () => {
+    describe('shortnameToUtf8', () => {
         it('converts valid shortnames', function() {
         it('converts valid shortnames', function() {
-            expect(shortnameToUnicode('+1')).toEqual('\ud83d\udc4d\ufe0f');
-            expect(shortnameToUnicode('thumbsup')).toEqual('\ud83d\udc4d\ufe0f');
+            expect(shortnameToUtf8('+1')).toEqual('\ud83d\udc4d\ufe0f');
+            expect(shortnameToUtf8('thumbsup')).toEqual('\ud83d\udc4d\ufe0f');
         });
         });
 
 
         it('returns null for unknown shortcodes', function() {
         it('returns null for unknown shortcodes', function() {
-            expect(shortnameToUnicode('sömbsöp')).toBeNull();
+            expect(shortnameToUtf8('sömbsöp')).toBeNull();
         });
         });
 
 
         it('handles multi-codepoint emoji', function() {
         it('handles multi-codepoint emoji', function() {
-            expect(shortnameToUnicode('flag_ch')).toEqual('\ud83c\udde8\ud83c\udded');
+            expect(shortnameToUtf8('flag_ch')).toEqual('\ud83c\udde8\ud83c\udded');
         });
         });
     });
     });