mirror of
https://github.com/bitwarden/web
synced 2025-12-06 00:03:28 +00:00
Add support for emojis in Avatar (#1074)
This commit is contained in:
2
jslib
2
jslib
Submodule jslib updated: 119699b82c...75fff66f98
@@ -58,7 +58,12 @@ export class AvatarComponent implements OnChanges, OnInit {
|
||||
chars = this.getFirstLetters(upperData, this.charCount);
|
||||
}
|
||||
if (chars == null) {
|
||||
chars = upperData.substr(0, this.charCount);
|
||||
chars = this.unicodeSafeSubstring(upperData, this.charCount);
|
||||
}
|
||||
|
||||
// If the chars contain an emoji, only show it.
|
||||
if (chars.match(Utils.regexpEmojiPresentation)) {
|
||||
chars = chars.match(Utils.regexpEmojiPresentation)[0];
|
||||
}
|
||||
|
||||
const charObj = this.getCharText(chars);
|
||||
@@ -91,7 +96,7 @@ export class AvatarComponent implements OnChanges, OnInit {
|
||||
if (parts.length > 1) {
|
||||
let text = '';
|
||||
for (let i = 0; i < count; i++) {
|
||||
text += parts[i].substr(0, 1);
|
||||
text += this.unicodeSafeSubstring(parts[i], 1);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
@@ -125,4 +130,9 @@ export class AvatarComponent implements OnChanges, OnInit {
|
||||
textTag.style.fontSize = this.fontSize + 'px';
|
||||
return textTag;
|
||||
}
|
||||
|
||||
private unicodeSafeSubstring(str: string, count: number) {
|
||||
const characters = str.match(/./ug);
|
||||
return characters != null ? characters.slice(0, count).join('') : '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user