Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2243ae17 authored by Roozbeh Pournader's avatar Roozbeh Pournader
Browse files

Make Html#toHTML() generate correct bidi directions.

Previously, after the first paragraph, the the detected bidi
direction of the text in the last paragraph was used, nstead of the
detected bidi direction of the current one.

Bug: 12027356
Change-Id: I51622a3156f1e321f53f7ca1855bc37aa6f77319
parent 2a16460c
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -244,13 +244,18 @@ public class Html {
                next++;
            }

            withinParagraph(out, text, i, next - nl, nl, next == end);
            if (withinParagraph(out, text, i, next - nl, nl, next == end)) {
                /* Paragraph should be closed */
                out.append("</p>\n");
                out.append(getOpenParaTagWithDirection(text, next, end));
            }
        }

        out.append("</p>\n");
    }

    private static void withinParagraph(StringBuilder out, Spanned text,
    /* Returns true if the caller should close and reopen the paragraph. */
    private static boolean withinParagraph(StringBuilder out, Spanned text,
                                        int start, int end, int nl,
                                        boolean last) {
        int next;
@@ -363,17 +368,14 @@ public class Html {
            }
        }

        String p = last ? "" : "</p>\n" + getOpenParaTagWithDirection(text, start, end);

        if (nl == 1) {
            out.append("<br>\n");
        } else if (nl == 2) {
            out.append(p);
            return false;
        } else {
            for (int i = 2; i < nl; i++) {
                out.append("<br>");
            }
            out.append(p);
            return !last;
        }
    }