From 44a6f91bc510fe081104b55255451bd5375c64ce Mon Sep 17 00:00:00 2001 From: MizuKuma <33080670+Arktische@users.noreply.github.com> Date: Tue, 3 Dec 2024 19:02:21 +0800 Subject: [PATCH] Fix broken pre-edit markedText on iOS and solve #17523 (#17618) * fix: add missing ref keyword to CombinedSpan3.CopyFromSpan * fix: fix incorrect indent in IUITextInput.TextInRange and boundary condition for surroundingText --------- Co-authored-by: Max Katz --- src/iOS/Avalonia.iOS/CombinedSpan3.cs | 8 ++++---- src/iOS/Avalonia.iOS/TextInputResponder.cs | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/iOS/Avalonia.iOS/CombinedSpan3.cs b/src/iOS/Avalonia.iOS/CombinedSpan3.cs index 13faea18486..e9fda8e4899 100644 --- a/src/iOS/Avalonia.iOS/CombinedSpan3.cs +++ b/src/iOS/Avalonia.iOS/CombinedSpan3.cs @@ -16,7 +16,7 @@ public CombinedSpan3(ReadOnlySpan span1, ReadOnlySpan span2, ReadOnlySpan< public int Length => Span1.Length + Span2.Length + Span3.Length; - static void CopyFromSpan(ReadOnlySpan from, int offset, ref Span to) + static void CopyFromSpan(ReadOnlySpan from, ref int offset, ref Span to) { if(to.Length == 0) return; @@ -33,8 +33,8 @@ static void CopyFromSpan(ReadOnlySpan from, int offset, ref Span to) public void CopyTo(Span to, int offset) { - CopyFromSpan(Span1, offset, ref to); - CopyFromSpan(Span2, offset, ref to); - CopyFromSpan(Span3, offset, ref to); + CopyFromSpan(Span1, ref offset, ref to); + CopyFromSpan(Span2, ref offset, ref to); + CopyFromSpan(Span3, ref offset, ref to); } } diff --git a/src/iOS/Avalonia.iOS/TextInputResponder.cs b/src/iOS/Avalonia.iOS/TextInputResponder.cs index 97b104b9184..b1575645c8a 100644 --- a/src/iOS/Avalonia.iOS/TextInputResponder.cs +++ b/src/iOS/Avalonia.iOS/TextInputResponder.cs @@ -220,15 +220,17 @@ string IUITextInput.TextInRange(UITextRange range) string result = ""; if (string.IsNullOrEmpty(_markedText)) + { if(surroundingText != null && r.EndIndex < surroundingText.Length) { result = surroundingText[r.StartIndex..r.EndIndex]; } + } else { var span = new CombinedSpan3(surroundingText.AsSpan().Slice(0, currentSelection.Start), _markedText, - surroundingText.AsSpan().Slice(currentSelection.Start)); + surroundingText.AsSpan().Slice(currentSelection.Start, currentSelection.End - currentSelection.Start)); var buf = new char[r.EndIndex - r.StartIndex]; span.CopyTo(buf, r.StartIndex); result = new string(buf);