Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b221e553 authored by Putta Khunchalee's avatar Putta Khunchalee Committed by Steve Kondik
Browse files

Fixing getOffsetBefore and getOffsetAfter to working properly on non-spacing...

Fixing getOffsetBefore and getOffsetAfter to working properly on non-spacing mark character. This will make moving cursor to the left and right to work properly on non-spacing mark character.

Change-Id: I6839e6b76b9c370c92d7452cce1ba556418f23c3
parent 3584116c
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.util.Printer;

import com.android.internal.util.ArrayUtils;

import java.text.Normalizer;
import java.util.regex.Pattern;
import java.util.Iterator;

@@ -856,7 +857,21 @@ public class TextUtils {
            else
                offset -= 1;
        } else {
            String decomposed = Normalizer.normalize(Character.toString(c), Normalizer.Form.NFKD);

            offset -= 1;
            c = decomposed.charAt(0);

            while (Character.getDirectionality(c) == Character.DIRECTIONALITY_NONSPACING_MARK) {
                offset -= 1;

                if (offset == 0)
                    break;

                decomposed = Normalizer.normalize(text.subSequence(offset, offset + 1),
                                                    Normalizer.Form.NFKD);
                c = decomposed.charAt(0);
            }
        }

        if (text instanceof Spanned) {
@@ -894,6 +909,18 @@ public class TextUtils {
                offset += 1;
        } else {
            offset += 1;

            do {
                String decomposed = Normalizer.normalize(text.subSequence(offset, offset + 1),
                                                        Normalizer.Form.NFKD);

                c = decomposed.charAt(0);

                if (Character.getDirectionality(c) != Character.DIRECTIONALITY_NONSPACING_MARK)
                    break;

                offset += 1;
            } while (offset < len);
        }

        if (text instanceof Spanned) {
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.view.KeyEvent;
import android.view.View;
import android.text.*;
import android.text.method.TextKeyListener.Capitalize;
import android.text.style.ReplacementSpan;
import android.widget.TextView;

public abstract class BaseKeyListener
@@ -54,7 +55,7 @@ implements KeyListener {
        } else if (altBackspace(view, content, keyCode, event)) {
            result = true;
        } else {
            int to = TextUtils.getOffsetBefore(content, selEnd);
            int to = (selEnd < 2) ? 0 : selEnd - 1;

            if (to != selEnd) {
                content.delete(Math.min(to, selEnd), Math.max(to, selEnd));