mirror of
https://github.com/bitwarden/browser.git
synced 2024-12-27 17:18:04 +01:00
Add support for emojis in Avatar (#1074)
This commit is contained in:
parent
e1e2edf2e9
commit
7c9ebed93f
2
jslib
2
jslib
@ -1 +1 @@
|
||||
Subproject commit 119699b82c26296cdd518c0c66e0cd3d61586309
|
||||
Subproject commit 75fff66f98e3d174baf369afbb747c1380fad4d4
|
@ -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('') : '';
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user