From f17630d5d2e9098724a1b225c6b0ec2d8cbb9829 Mon Sep 17 00:00:00 2001 From: iPel Date: Mon, 13 Nov 2023 23:10:58 +0800 Subject: [PATCH] fix(android): fix premature text truncation --- .../java/com/tencent/mtt/hippy/dom/node/TextNode.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/sdk/src/main/java/com/tencent/mtt/hippy/dom/node/TextNode.java b/android/sdk/src/main/java/com/tencent/mtt/hippy/dom/node/TextNode.java index cdf9ccf558d..227f043047d 100644 --- a/android/sdk/src/main/java/com/tencent/mtt/hippy/dom/node/TextNode.java +++ b/android/sdk/src/main/java/com/tencent/mtt/hippy/dom/node/TextNode.java @@ -853,7 +853,7 @@ private StaticLayout truncateLayoutWithNumberOfLine(Layout preLayout, int width, lastLine = ellipsizeMiddle(origin, measurePaint, width, start); } else /*if (MODE_TAIL.equals(mEllipsizeMode))*/ { measurePaint.setTextSize(getLineHeight(preLayout, numberOfLines - 1)); - int end = preLayout.getLineEnd(numberOfLines - 1); + int end = preLayout.getLineEnd(numberOfLines); lastLine = ellipsizeTail(origin, measurePaint, width, start, end); } // concat everything @@ -949,9 +949,9 @@ public void ellipsized(int l, int r) { } private CharSequence ellipsizeTail(CharSequence origin, TextPaint paint, int width, int start, int end) { - if (origin.charAt(end - 1) == '\n') { - // there will be an unexpected blank line, if ends with a new line char, trim it - --end; + int index = TextUtils.indexOf(origin, '\n', start, end); + if (index != -1) { + end = index; } // "${first line of the rest part}…" CharSequence tmp;