diff --git a/app/src/main/java/com/termux/api/ClipboardAPI.java b/app/src/main/java/com/termux/api/ClipboardAPI.java index 4a0a108..7f33998 100644 --- a/app/src/main/java/com/termux/api/ClipboardAPI.java +++ b/app/src/main/java/com/termux/api/ClipboardAPI.java @@ -24,7 +24,12 @@ public class ClipboardAPI { if (set) { ResultReturner.returnData(apiReceiver, intent, new ResultReturner.WithStringInput() { @Override - public void writeResult(PrintWriter out) throws Exception { + protected boolean trimInput() { + return false; + } + + @Override + public void writeResult(PrintWriter out) { clipboard.setPrimaryClip(ClipData.newPlainText("", inputString)); } }); diff --git a/app/src/main/java/com/termux/api/util/ResultReturner.java b/app/src/main/java/com/termux/api/util/ResultReturner.java index 8f4f726..ec57d8f 100644 --- a/app/src/main/java/com/termux/api/util/ResultReturner.java +++ b/app/src/main/java/com/termux/api/util/ResultReturner.java @@ -49,6 +49,10 @@ public abstract class ResultReturner { public static abstract class WithStringInput extends WithInput { protected String inputString; + protected boolean trimInput() { + return true; + } + @Override public final void setInput(InputStream inputStream) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -57,7 +61,8 @@ public abstract class ResultReturner { while ((l = inputStream.read(buffer)) > 0) { baos.write(buffer, 0, l); } - inputString = new String(baos.toByteArray(), StandardCharsets.UTF_8).trim(); + inputString = new String(baos.toByteArray(), StandardCharsets.UTF_8); + if (trimInput()) inputString = inputString.trim(); } }