From 58e1396c15bc0eb3e628f8324e27f2f258fa82dd Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 4 Oct 2024 22:39:10 +0200 Subject: [PATCH] Fix rich text box snapping to be ignored at text end #2964 --- Source/Engine/UI/GUI/Common/RichTextBoxBase.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs index 17dc25e16..4a49f5bad 100644 --- a/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs +++ b/Source/Engine/UI/GUI/Common/RichTextBoxBase.cs @@ -280,11 +280,16 @@ namespace FlaxEngine.GUI GetNearestTextBlock(end, out TextBlock endTextBlock, !movingBack); snappedStart = startTextBlock.Range.Contains(start) ? start : (movingBack ? startTextBlock.Range.EndIndex - 1 : startTextBlock.Range.StartIndex); - snappedEnd = endTextBlock.Range.Contains(end) ? end : (movingBack ? endTextBlock.Range.EndIndex - 1 : endTextBlock.Range.StartIndex); snappedStart = movingBack ? Math.Min(start, snappedStart) : Math.Max(start, snappedStart); snappedEnd = movingBack ? Math.Min(end, snappedEnd) : Math.Max(end, snappedEnd); + + // Don't snap if selection is right in the end of the text + if (start == _text.Length) + snappedStart = _text.Length; + if (end == _text.Length) + snappedEnd = _text.Length; } base.SetSelection(snappedStart, snappedEnd, withScroll);