Skip to content

Commit b0dc4fa

Browse files
committed
fix: "πŸ‘¨πŸ»β€β€οΈβ€πŸ’‹β€πŸ‘¨πŸ»" is supposed to count as 1char
1 parent 6ae36bd commit b0dc4fa

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

β€Žts/components/dialog/UpdateConversationDetailsDialog.tsxβ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,12 @@ function useDescriptionErrorString({
101101
// description is always optional
102102
return '';
103103
}
104-
const charLength = newDescription?.length || 0;
104+
105+
// "πŸ‘¨πŸ»β€β€οΈβ€πŸ’‹β€πŸ‘¨πŸ»" is supposed to be 1char, but 35 bytes, and this is the only way
106+
// I found to have this to have the correct count
107+
const segmenter = new Intl.Segmenter('en', { granularity: 'grapheme' });
108+
const charLength = [...segmenter.segment(newDescription)].length;
109+
105110
const byteLength = new TextEncoder().encode(newDescription).length;
106111

107112
if (

0 commit comments

Comments
Β (0)