From c769c4dd74bc2f15ca7b0ad6523dc128d48352da Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 12 Jan 2022 21:20:37 +0300 Subject: [PATCH] Various Fixes --- submodules/Display/Source/TextNode.swift | 5 ++--- .../Sources/InvisibleInkDustNode.swift | 3 +-- .../Sources/ServiceMessageStrings.swift | 15 ++++++++++----- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/submodules/Display/Source/TextNode.swift b/submodules/Display/Source/TextNode.swift index aa9c4aa0d8..e669ea6f11 100644 --- a/submodules/Display/Source/TextNode.swift +++ b/submodules/Display/Source/TextNode.swift @@ -1073,7 +1073,6 @@ public class TextNode: ASDisplayNode { break } } -// brokenLineRange.length = CTLineGetGlyphCount(coreTextLine) - 1 if brokenLineRange.location + brokenLineRange.length > attributedString.length { brokenLineRange.length = attributedString.length - brokenLineRange.location } @@ -1338,7 +1337,7 @@ public class TextNode: ASDisplayNode { context.saveGState() var clipRects: [CGRect] = [] for spoiler in line.spoilerWords { - var spoilerClipRect = spoiler.frame.offsetBy(dx: lineFrame.minX, dy: lineFrame.minY) + var spoilerClipRect = spoiler.frame.offsetBy(dx: lineFrame.minX, dy: lineFrame.minY - UIScreenPixel) spoilerClipRect.size.height += 1.0 + UIScreenPixel clipRects.append(spoilerClipRect) } @@ -1375,7 +1374,7 @@ public class TextNode: ASDisplayNode { context.restoreGState() } else { for spoiler in line.spoilerWords { - var spoilerClearRect = spoiler.frame.offsetBy(dx: lineFrame.minX, dy: lineFrame.minY) + var spoilerClearRect = spoiler.frame.offsetBy(dx: lineFrame.minX, dy: lineFrame.minY - UIScreenPixel) spoilerClearRect.size.height += 1.0 + UIScreenPixel clearRects.append(spoilerClearRect) } diff --git a/submodules/InvisibleInkDustNode/Sources/InvisibleInkDustNode.swift b/submodules/InvisibleInkDustNode/Sources/InvisibleInkDustNode.swift index 6e197df68d..feeb97d394 100644 --- a/submodules/InvisibleInkDustNode/Sources/InvisibleInkDustNode.swift +++ b/submodules/InvisibleInkDustNode/Sources/InvisibleInkDustNode.swift @@ -122,7 +122,6 @@ public class InvisibleInkDustNode: ASDisplayNode { emitterLayer.emitterSize = CGSize(width: 1, height: 1) emitterLayer.emitterShape = CAEmitterLayerEmitterShape(rawValue: "rectangles") emitterLayer.setValue(behaviors, forKey: "emitterBehaviors") -// emitterLayer.setValue(0.0322, forKey: "updateInterval") emitterLayer.setValue(4.0, forKeyPath: "emitterBehaviors.fingerAttractor.stiffness") emitterLayer.setValue(false, forKeyPath: "emitterBehaviors.fingerAttractor.enabled") @@ -188,7 +187,7 @@ public class InvisibleInkDustNode: ASDisplayNode { var scaleAddition = maxFactor * 4.0 var durationAddition = -maxFactor * 0.2 - if self.emitterNode.frame.height > 0.0, self.emitterNode.frame.width / self.emitterNode.frame.height < 0.3 { + if self.emitterNode.frame.height > 0.0, self.emitterNode.frame.width / self.emitterNode.frame.height < 0.7 { scaleAddition *= 5.0 durationAddition *= 2.0 } diff --git a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift index 1ffeb48bbb..817b0f3662 100644 --- a/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift +++ b/submodules/TelegramStringFormatting/Sources/ServiceMessageStrings.swift @@ -252,17 +252,22 @@ public func universalServiceMessageString(presentationData: (PresentationTheme, } let string = textWithRanges._tuple.0 - let stringLength = (clippedText as NSString).length + let stringLength = (string as NSString).length + let messageLength = (clippedText as NSString).length var ranges = textWithRanges._tuple.1 let entityOffset = ranges.first(where: { $0.0 == 1 })?.1.location ?? 0 var attributes = peerMentionsAttributes(primaryTextColor: primaryTextColor, peerIds: [(0, message.author?.id)]) for entity in entities { - if entity.range.startIndex >= stringLength { + if entity.range.startIndex >= messageLength { continue } - let index = ranges.count - ranges.append((ranges.count, NSRange(location: entityOffset + entity.range.startIndex, length: entity.range.count))) - attributes[index] = spoilerAttributes(primaryTextColor: primaryTextColor) + let location = entityOffset + entity.range.startIndex + let length = max(0, min(entity.range.count, stringLength - location - 1)) + if length > 0 { + let index = ranges.count + ranges.append((ranges.count, NSRange(location: location, length: length))) + attributes[index] = spoilerAttributes(primaryTextColor: primaryTextColor) + } } attributedString = addAttributesToStringWithRanges((string, ranges), body: bodyAttributes, argumentAttributes: attributes) case .game: