From 040c76a451d923afca1e85b51eacc96360ec6e12 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 14 Jul 2020 08:57:46 +0200 Subject: [PATCH] Word break preview text --- .../main/java/eu/faircode/email/HtmlHelper.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 0d4bdf500d..6ed24164b8 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -1577,11 +1577,18 @@ public class HtmlHelper { if (full) return text; - String preview = text.substring(0, Math.min(text.length(), PREVIEW_SIZE)); - if (preview.length() < text.length()) - preview += "…"; + return truncate(text, PREVIEW_SIZE); + } - return preview; + static String truncate(String text, int at) { + if (text.length() < at) + return text; + + String preview = text.substring(0, at); + int space = preview.lastIndexOf(' '); + if (space > 0) + preview = preview.substring(0, space + 1); + return preview + "…"; } static String getText(Context context, String html) {