www.fgks.org   »   [go: up one dir, main page]

Skip to content

Commit

Permalink
Merge quotes before sending
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali committed Oct 29, 2023
1 parent 37e8618 commit 333011a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Expand Up @@ -27,8 +27,8 @@ public enum MessageTextEntityType: Equatable {
}

public struct MessageTextEntity: PostboxCoding, Codable, Equatable {
public let range: Range<Int>
public let type: MessageTextEntityType
public var range: Range<Int>
public var type: MessageTextEntityType

public init(range: Range<Int>, type: MessageTextEntityType) {
self.range = range
Expand Down
29 changes: 29 additions & 0 deletions submodules/TextFormat/Sources/GenerateTextEntities.swift
Expand Up @@ -181,6 +181,35 @@ public func generateChatInputTextEntities(_ text: NSAttributedString, maxAnimate
}
}

while true {
var hadReductions = false

scan: for i in 0 ..< entities.count {
if case .BlockQuote = entities[i].type {
inner: for j in 0 ..< entities.count {
if j == i {
continue inner
}
if case .BlockQuote = entities[j].type {
if entities[i].range.upperBound == entities[j].range.lowerBound || entities[i].range.lowerBound == entities[j].range.upperBound {
entities[i].range = min(entities[i].range.lowerBound, entities[j].range.lowerBound) ..< max(entities[i].range.upperBound, entities[j].range.upperBound)
entities.remove(at: j)

hadReductions = true
break scan
}
}
}

break scan
}
}

if !hadReductions {
break
}
}

return entities
}

Expand Down

0 comments on commit 333011a

Please sign in to comment.