Skip to content

feat: pangu sending and receiving text for CJK#246

Open
NextAlone wants to merge 3 commits intoTDesktop-x64:devfrom
NextAlone:dev
Open

feat: pangu sending and receiving text for CJK#246
NextAlone wants to merge 3 commits intoTDesktop-x64:devfrom
NextAlone:dev

Conversation

@NextAlone
Copy link
Copy Markdown

Signed-off-by: Next Alone <12210746+NextAlone@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 7, 2026 16:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_send and pangu_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.

Comment thread Telegram/SourceFiles/core/pangu_spacing.h Outdated
Comment on lines +120 to +129
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);
}
}
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +507 to 511
if (GetEnhancedBool("pangu_spacing_receive")) {
textWithEntities =
PanguSpacing::SpacingTextWithEntities(textWithEntities);
}
setText(_media ? textWithEntities : EnsureNonEmpty(textWithEntities));
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
NextAlone and others added 2 commits February 12, 2026 14:29
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants