Skip to content

Commit 9c2acfc

Browse files
committed
Fix run out of range
1 parent 3630187 commit 9c2acfc

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Telegram/Common/TextStyleRun.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ public static IList<TextEntity> GetEntities(string text, IList<TextStyleRun> run
198198

199199
foreach (var run in runs)
200200
{
201+
if (run.End > text.Length)
202+
{
203+
if (run.Start < text.Length)
204+
{
205+
run.End = text.Length;
206+
}
207+
else
208+
{
209+
continue;
210+
}
211+
}
212+
201213
if (run.HasFlag(TextStyle.Emoji))
202214
{
203215
Create(run.Offset, run.Length, results, run.Type);

Telegram/Controls/FormattedTextBox.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ public FormattedText GetFormattedText(bool clear = false, bool parseMarkdown = t
10371037
_reusableRange.SetRange(0, _reusableRange.StoryLength - 1);
10381038

10391039
range = _reusableRange;
1040-
storyLength = range.StoryLength;
1040+
storyLength = range.StoryLength - 1;
10411041
hidden = 0;
10421042
}
10431043

@@ -1056,7 +1056,7 @@ public FormattedText GetFormattedText(bool clear = false, bool parseMarkdown = t
10561056
range.Collapse(true);
10571057
}
10581058

1059-
while (range.EndPosition < storyLength - 1)
1059+
while (range.EndPosition < storyLength)
10601060
{
10611061
var startPos = range.StartPosition;
10621062
var shouldBreak = false;

0 commit comments

Comments
 (0)