From e480958234ae1b019bacf1b9cab85c34a23598ac Mon Sep 17 00:00:00 2001 From: Nikita Dubrovsky Date: Wed, 5 May 2021 10:44:56 -0700 Subject: [PATCH] Make drop consistent with paste for multiple text items in a ClipData A ClipData can contain multiple items, for example: ``` ClipData clip = ClipData.newPlainText("label", "ONE"); clip.addItem(new ClipData.Item("TWO")); clip.addItem(new ClipData.Item("THREE")); ``` When a clip like this is pasted, the TextView impl inserts a newline between each item. When the same clip is inserted via drag-and-drop, no newlines are inserted. This change makes the behavior of drop and paste consistent by updating drop to match the paste behavior (since pasting has been around longer and is more common). Bug: 187428338 Test: atest CtsWidgetTestCases:TextViewReceiveContentTest Change-Id: I08f30e619b858a4586ab9b4ed287be28b218231e --- .../widget/TextViewOnReceiveContentListener.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/core/java/android/widget/TextViewOnReceiveContentListener.java b/core/java/android/widget/TextViewOnReceiveContentListener.java index 0d5bf71dc9559..6a966e0b6d3ff 100644 --- a/core/java/android/widget/TextViewOnReceiveContentListener.java +++ b/core/java/android/widget/TextViewOnReceiveContentListener.java @@ -19,7 +19,6 @@ package android.widget; import static android.content.ContentResolver.SCHEME_CONTENT; import static android.view.ContentInfo.FLAG_CONVERT_TO_PLAIN_TEXT; import static android.view.ContentInfo.SOURCE_AUTOFILL; -import static android.view.ContentInfo.SOURCE_DRAG_AND_DROP; import static android.view.ContentInfo.SOURCE_INPUT_METHOD; import android.annotation.NonNull; @@ -82,10 +81,6 @@ public final class TextViewOnReceiveContentListener implements OnReceiveContentL onReceiveForAutofill((TextView) view, payload); return null; } - if (source == SOURCE_DRAG_AND_DROP) { - onReceiveForDragAndDrop((TextView) view, payload); - return null; - } // The code here follows the original paste logic from TextView: // https://cs.android.com/android/_/android/platform/frameworks/base/+/9fefb65aa9e7beae9ca8306b925b9fbfaeffecc9:core/java/android/widget/TextView.java;l=12644 @@ -147,13 +142,6 @@ public final class TextViewOnReceiveContentListener implements OnReceiveContentL Selection.setSelection(editable, editable.length()); } - private static void onReceiveForDragAndDrop(@NonNull TextView view, - @NonNull ContentInfo payload) { - final CharSequence text = coerceToText(payload.getClip(), view.getContext(), - payload.getFlags()); - replaceSelection((Editable) view.getText(), text); - } - private static @NonNull CharSequence coerceToText(@NonNull ClipData clip, @NonNull Context context, @Flags int flags) { SpannableStringBuilder ssb = new SpannableStringBuilder();