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

Commit 8edcadc0 authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Update ALT+DEL/FORWARD_DEL behavior

Old behavior
ALT+DEL: delete entire line
ALT+FORWARD_DEL: delete entire line

New behavior
ALT+DEL: delete characters after the cursor until line end offset.
ALT_FORWARD_DEL: delete characters before the cursor until line start offset.

Bug: 279723106
Test: atest android.text.method.cts.BaseKeyListenerTest
Change-Id: I725a929a224a2087b8809e5862d433ec113d67c0
parent 41d88dd5
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -345,7 +345,7 @@ public abstract class BaseKeyListener extends MetaKeyKeyListener
        }

        // Alt+Backspace or Alt+ForwardDelete deletes the current line, if possible.
        if (isAltActive && deleteLine(view, content)) {
        if (isAltActive && deleteLineFromCursor(view, content, isForwardDelete)) {
            return true;
        }

@@ -438,18 +438,34 @@ public abstract class BaseKeyListener extends MetaKeyKeyListener
        return false;
    }

    private boolean deleteLine(View view, Editable content) {
    private boolean deleteLineFromCursor(View view, Editable content, boolean forward) {
        if (view instanceof TextView) {
            final int selectionStart = Selection.getSelectionStart(content);
            final int selectionEnd = Selection.getSelectionEnd(content);
            final int selectionMin;
            final int selectionMax;
            if (selectionStart < selectionEnd) {
                selectionMin = selectionStart;
                selectionMax = selectionEnd;
            } else {
                selectionMin = selectionEnd;
                selectionMax = selectionStart;
            }

            final TextView textView = (TextView) view;
            final Layout layout = textView.getLayout();
            if (layout != null && !textView.isOffsetMappingAvailable()) {
                final int line = layout.getLineForOffset(Selection.getSelectionStart(content));
                final int start = layout.getLineStart(line);
                final int end = layout.getLineEnd(line);
                if (end != start) {
                    content.delete(start, end);
                    return true;

                if (forward) {
                    content.delete(selectionMin, end);
                } else {
                    content.delete(start, selectionMax);
                }

                return true;
            }
        }
        return false;