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

Conversation

Arktische
Copy link
Contributor

@Arktische Arktische commented Nov 26, 2024

What does the pull request do?

Fix #17523.

What is the current behavior?

Can't type any multisyllable language including Chinese, Korean etc.

Bug Descrption

The CombinedSpan3.CopyFromSpan implementaion is wrong.

    static void CopyFromSpan(ReadOnlySpan<T> from, int offset, ref Span<T> to)
    {
        if(to.Length == 0)
            return;
        if (offset < from.Length)
        {
            var copyNow = Math.Min(from.Length - offset, to.Length);
            from.Slice(offset, copyNow).CopyTo(to);
            to = to.Slice(copyNow);
            offset = 0;
        }
        else
            offset -= from.Length;
    }


    public void CopyTo(Span<T> to, int offset)
    {
   // the offset is not updated, should use ref here
        CopyFromSpan(Span1, offset, ref to);
        CopyFromSpan(Span2, offset, ref to);
        CopyFromSpan(Span3, offset, ref to);
    }

Another bug occurs in IUITextInput.TextInRange

        string IUITextInput.TextInRange(UITextRange range)
        {
            var r = (AvaloniaTextRange)range;
            var surroundingText = _client.SurroundingText;
            var currentSelection = _client.Selection;
            Logger.TryGet(LogEventLevel.Debug, ImeLog)?.Log(null, "IUIKeyInput.TextInRange {start} {end}", r.StartIndex, r.EndIndex);

            string result = "";
// wrong indent here, it will directly fallback when _markedText is empty or null
            if (string.IsNullOrEmpty(_markedText)) 
                if(surroundingText != null && r.EndIndex < surroundingText.Length)
                {
                    result = surroundingText[r.StartIndex..r.EndIndex];
                }
// this `else` is paired with the second `if`, not as expected
            else
            {
                var span = new CombinedSpan3<char>(surroundingText.AsSpan().Slice(0, currentSelection.Start),
                    _markedText,
                    surroundingText.AsSpan().Slice(currentSelection.Start));
                var buf = new char[r.EndIndex - r.StartIndex];
                span.CopyTo(buf, r.StartIndex);
                result = new string(buf);
            }
            Logger.TryGet(LogEventLevel.Debug, ImeLog)?.Log(null, "result: {res}", result);
            return result;
        }

What is the updated/expected behavior with this PR?

Able to input Chinese or other multisyllable languages using system IME on iOS

How was the solution implemented (if it's not obvious)?

Implementions are simple as commits showed.

Checklist

Since this fix is simple, those steps could be omitted

Breaking changes

None

Obsoletions / Deprecations

None

Fixed issues

#17523

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
mauromorales Mauro Morales

Verified

This commit was signed with the committer’s verified signature.
mauromorales Mauro Morales
…ndition for surroundingText
@maxkatz6 maxkatz6 added bug os-ios backport-candidate-11.2.x Consider this PR for backporting to 11.2 branch labels Nov 27, 2024
Copy link
Member

@maxkatz6 maxkatz6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Arktische and others added 2 commits November 30, 2024 18:49

Verified

This commit was signed with the committer’s verified signature.
mauromorales Mauro Morales

Verified

This commit was signed with the committer’s verified signature.
mauromorales Mauro Morales
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0053627-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Nov 30, 2024

  • All contributors have signed the CLA.

Sorry, something went wrong.

@kerams
Copy link
Contributor

kerams commented Nov 30, 2024

Many thanks, pinyin input now works great. No change in Korean though, which probably points to a different underlying problem.

@Arktische
Copy link
Contributor Author

@cla-avalonia agree

@maxkatz6 maxkatz6 added this pull request to the merge queue Dec 3, 2024
Merged via the queue into AvaloniaUI:master with commit 44a6f91 Dec 3, 2024
10 checks passed
maxkatz6 added a commit that referenced this pull request Dec 19, 2024

Verified

This commit was signed with the committer’s verified signature.
mauromorales Mauro Morales
* 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 <maxkatz6@outlook.com>
@maxkatz6 maxkatz6 added backported-11.2.x and removed backport-candidate-11.2.x Consider this PR for backporting to 11.2 branch labels Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to type Chinese with pinyin layout
5 participants