mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
Merge pull request #3680 from deltachat/adb/paste-as-plain-text
force "paste as plain text" in composer
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
* add mute option "8 hours"
|
||||
* add menu option to easily save/unsave selected message
|
||||
* improve deletion confirmation for "Device Messages"
|
||||
* always paste as plain text in message draft area
|
||||
|
||||
## v1.54.4
|
||||
2025-03
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
package org.thoughtcrime.securesms.components;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.widget.AppCompatEditText;
|
||||
import androidx.core.view.ContentInfoCompat;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.inputmethod.EditorInfoCompat;
|
||||
import androidx.core.view.inputmethod.InputConnectionCompat;
|
||||
import androidx.core.view.inputmethod.InputContentInfoCompat;
|
||||
@@ -50,6 +53,28 @@ public class ComposeText extends AppCompatEditText {
|
||||
initialize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTextContextMenuItem(int id) {
|
||||
if (id == android.R.id.paste) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
id = android.R.id.pasteAsPlainText;
|
||||
} else if (ViewCompat.getOnReceiveContentMimeTypes(this) != null) {
|
||||
// older device, manually paste as plain text
|
||||
ClipboardManager cm = (ClipboardManager) getContext().getSystemService(
|
||||
Context.CLIPBOARD_SERVICE);
|
||||
ClipData clip = (cm == null) ? null : cm.getPrimaryClip();
|
||||
if (clip != null && clip.getItemCount() > 0) {
|
||||
ContentInfoCompat payload = new ContentInfoCompat.Builder(clip, ContentInfoCompat.SOURCE_CLIPBOARD)
|
||||
.setFlags(ContentInfoCompat.FLAG_CONVERT_TO_PLAIN_TEXT)
|
||||
.build();
|
||||
ViewCompat.performReceiveContent(this, payload);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onTextContextMenuItem(id);
|
||||
}
|
||||
|
||||
public String getTextTrimmed(){
|
||||
return getText().toString().trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user