mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 09:05:20 +00:00
Fix URL detection and message spacing
- Add URL detection to message formatting with blue color and underline - Replace List with ScrollView for precise spacing control - Use minimal vertical padding (1px) between messages - Remove LazyLinkPreviewView, use LinkPreviewView directly - URLs now appear highlighted in message text AND show preview below
This commit is contained in:
@@ -988,8 +988,12 @@ class ChatViewModel: ObservableObject {
|
||||
let hashtagRegex = try? NSRegularExpression(pattern: hashtagPattern, options: [])
|
||||
let mentionRegex = try? NSRegularExpression(pattern: mentionPattern, options: [])
|
||||
|
||||
// Use NSDataDetector for URL detection
|
||||
let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
|
||||
|
||||
let hashtagMatches = hashtagRegex?.matches(in: content, options: [], range: NSRange(location: 0, length: content.count)) ?? []
|
||||
let mentionMatches = mentionRegex?.matches(in: content, options: [], range: NSRange(location: 0, length: content.count)) ?? []
|
||||
let urlMatches = detector?.matches(in: content, options: [], range: NSRange(location: 0, length: content.count)) ?? []
|
||||
|
||||
// Combine and sort matches
|
||||
var allMatches: [(range: NSRange, type: String)] = []
|
||||
@@ -999,6 +1003,9 @@ class ChatViewModel: ObservableObject {
|
||||
for match in mentionMatches {
|
||||
allMatches.append((match.range(at: 0), "mention"))
|
||||
}
|
||||
for match in urlMatches {
|
||||
allMatches.append((match.range, "url"))
|
||||
}
|
||||
allMatches.sort { $0.range.location < $1.range.location }
|
||||
|
||||
// Build content with styling
|
||||
@@ -1029,6 +1036,9 @@ class ChatViewModel: ObservableObject {
|
||||
matchStyle.underlineStyle = .single
|
||||
} else if type == "mention" {
|
||||
matchStyle.foregroundColor = Color.orange
|
||||
} else if type == "url" {
|
||||
matchStyle.foregroundColor = Color.blue
|
||||
matchStyle.underlineStyle = .single
|
||||
}
|
||||
|
||||
result.append(AttributedString(matchText).mergingAttributes(matchStyle))
|
||||
|
||||
Reference in New Issue
Block a user