From 7a8b7b74dfc265aa2ee854e0c16660f6b9d708d9 Mon Sep 17 00:00:00 2001 From: Nikita Mitasov Date: Wed, 19 Aug 2026 20:52:34 +0300 Subject: [PATCH] Fix mention detection inside email addresses --- .../TextFormat/Sources/GenerateTextEntities.swift | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/submodules/TextFormat/Sources/GenerateTextEntities.swift b/submodules/TextFormat/Sources/GenerateTextEntities.swift index ea64fb5e9db..da6ae11781c 100644 --- a/submodules/TextFormat/Sources/GenerateTextEntities.swift +++ b/submodules/TextFormat/Sources/GenerateTextEntities.swift @@ -35,6 +35,11 @@ private let identifierDelimiterSet: CharacterSet = { set.insert("/") return set }() +private let mentionDelimiterSet: CharacterSet = { + var set = CharacterSet.whitespacesAndNewlines + set.insert("(") + return set +}() private let externalIdentifierDelimiterSet: CharacterSet = { var set = identifierDelimiterSet set.remove(".") @@ -329,14 +334,20 @@ public func generateTextEntities(_ text: String, enabledTypes: EnabledEntityType } } else if scalar == "@" { notFound = false + let isMentionBoundary: Bool + if let previousScalar = previousScalar { + isMentionBoundary = mentionDelimiterSet.contains(previousScalar) + } else { + isMentionBoundary = true + } if let (type, range) = currentEntity { if case .command = type { currentEntity = (type, range.lowerBound ..< utf16.index(after: index)) } else { commitEntity(utf16, type, range, enabledTypes, &entities) - currentEntity = (.mention, index ..< index) + currentEntity = isMentionBoundary ? (.mention, index ..< index) : nil } - } else { + } else if isMentionBoundary { currentEntity = (.mention, index ..< index) } } else if scalar == "#" {