Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken pre-edit markedText on iOS and solve #17523 #17618

Merged
merged 4 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/iOS/Avalonia.iOS/CombinedSpan3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public CombinedSpan3(ReadOnlySpan<T> span1, ReadOnlySpan<T> span2, ReadOnlySpan<

public int Length => Span1.Length + Span2.Length + Span3.Length;

static void CopyFromSpan(ReadOnlySpan<T> from, int offset, ref Span<T> to)
static void CopyFromSpan(ReadOnlySpan<T> from, ref int offset, ref Span<T> to)
{
if(to.Length == 0)
return;
Expand All @@ -33,8 +33,8 @@ static void CopyFromSpan(ReadOnlySpan<T> from, int offset, ref Span<T> to)

public void CopyTo(Span<T> 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);
}
}
4 changes: 3 additions & 1 deletion src/iOS/Avalonia.iOS/TextInputResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<char>(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);
Expand Down
Loading