feat: pangu sending and receiving text for CJK#246
feat: pangu sending and receiving text for CJK#246NextAlone wants to merge 3 commits intoTDesktop-x64:devfrom
Conversation
Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds an optional “pangu spacing” feature to automatically insert spacing between CJK characters and adjacent ASCII alphanumerics, with separate toggles for outgoing messages and for displaying received messages.
Changes:
- Add Enhanced Settings UI toggles and persisted defaults for
pangu_spacing_sendandpangu_spacing_receive. - Apply spacing transformation during message sending (text + media captions) and during message construction for received messages.
- Introduce a new
core/pangu_spacing.{h,cpp}module and wire it into the build.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Telegram/SourceFiles/settings/settings_enhanced.cpp | Adds two new toggle controls for send/receive spacing. |
| Telegram/SourceFiles/history/history_item.cpp | Applies spacing to received message TextWithEntities before storing via setText(). |
| Telegram/SourceFiles/core/pangu_spacing.h | Declares spacing helpers for plain text and TextWithEntities. |
| Telegram/SourceFiles/core/pangu_spacing.cpp | Implements the spacing algorithm and entity offset adjustments. |
| Telegram/SourceFiles/core/enhanced_settings.cpp | Adds defaults + persistence for the new settings keys. |
| Telegram/SourceFiles/apiwrap.cpp | Applies spacing to outgoing message text before preparing for sending. |
| Telegram/SourceFiles/api/api_sending.cpp | Applies spacing to outgoing captions for media/file sends. |
| Telegram/Resources/langs/lang.strings | Adds localized strings for the two new settings labels. |
| Telegram/CMakeLists.txt | Adds the new core module sources to the build. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (hasPrev) { | ||
| const auto prevIsCJK = IsCJK(prevCodePoint); | ||
| const auto currIsCJK = IsCJK(codePoint); | ||
| const auto prevIsAN = IsHalfWidthAlphaNumeric(prevCodePoint); | ||
| const auto currIsAN = IsHalfWidthAlphaNumeric(codePoint); | ||
|
|
||
| if ((prevIsCJK && currIsAN) || (prevIsAN && currIsCJK)) { | ||
| insertPositions.push_back(startPos); | ||
| } | ||
| } |
There was a problem hiding this comment.
SpacingTextWithEntities inserts spaces purely based on adjacent code points, without considering entity ranges. This can insert spaces inside entities like Url/Email/CustomUrl, mentions/hashtags/commands, or Code/Pre, which may break link targets, copy/paste, or code semantics (even though offsets are adjusted). Consider skipping insertions whose UTF-16 position falls within “verbatim” entity ranges (at least Code/Pre and link-like entities), or splitting entities around inserted spaces instead of expanding them.
| if (GetEnhancedBool("pangu_spacing_receive")) { | ||
| textWithEntities = | ||
| PanguSpacing::SpacingTextWithEntities(textWithEntities); | ||
| } | ||
| setText(_media ? textWithEntities : EnsureNonEmpty(textWithEntities)); |
There was a problem hiding this comment.
Receive-side spacing is applied before setText(...), so it mutates HistoryItem::_text and will propagate into features that use originalText() (copy, forward, edit, quotes, search previews, etc.), not just on-screen rendering. If the intent is truly “when displaying”, consider applying spacing at render time (or keeping a separate display-only text) so the underlying message content/entities remain identical to the server text.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Next Alone 12210746+NextAlone@users.noreply.github.com