diff --git a/pkg/channels/telegram.go b/pkg/channels/telegram.go index 23c1246af..d5863ec5a 100644 --- a/pkg/channels/telegram.go +++ b/pkg/channels/telegram.go @@ -771,6 +771,8 @@ func displayWidth(s string) int { continue case unicode.Is(unicode.Mn, r): continue + case isEmojiRune(r): + w += 3 case unicode.In(r, unicode.Han, unicode.Hiragana, @@ -787,6 +789,13 @@ func displayWidth(s string) int { return w } +func isEmojiRune(r rune) bool { + // Common emoji blocks + Dingbats/Stars used in rating tables. + return (r >= 0x1F300 && r <= 0x1FAFF) || // Misc emoji/pictographs/symbols + (r >= 0x2600 && r <= 0x27BF) || // Misc symbols + dingbats + r == 0x2B50 // WHITE MEDIUM STAR (⭐) +} + func wrapByDisplayWidth(s string, maxWidth int) []string { if maxWidth <= 0 { return []string{s} diff --git a/pkg/channels/telegram_test.go b/pkg/channels/telegram_test.go index ba0876721..6afcc1ff9 100644 --- a/pkg/channels/telegram_test.go +++ b/pkg/channels/telegram_test.go @@ -79,3 +79,10 @@ func TestMarkdownToTelegramHTML_TableWrapsLongCell(t *testing.T) { t.Fatalf("expected wrapped long cell content, got: %q", got) } } + +func TestDisplayWidth_EmojiIsThree(t *testing.T) { + got := displayWidth("⭐⭐⭐⭐⭐") + if got != 15 { + t.Fatalf("displayWidth(stars) = %d, want 15", got) + } +}