From 56ab27a49ecdf75e5355800071a462618fdfef69 Mon Sep 17 00:00:00 2001 From: Rajesh Malviya Date: Wed, 6 Nov 2024 10:22:28 +0530 Subject: [PATCH] wip --- lib/model/content.dart | 7 +++++-- lib/widgets/content.dart | 9 +++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/model/content.dart b/lib/model/content.dart index ccc84121dd..649c4d114e 100644 --- a/lib/model/content.dart +++ b/lib/model/content.dart @@ -4,6 +4,7 @@ import 'package:collection/collection.dart'; import 'package:flutter/foundation.dart'; import 'package:html/dom.dart' as dom; import 'package:html/parser.dart'; +import 'package:intl/intl.dart'; import '../api/model/model.dart'; import '../api/model/submessage.dart'; @@ -96,9 +97,10 @@ class PollContent implements ZulipMessageContent { /// [Stream.renderedDescription], or other text from a Zulip server that comes /// in the same Zulip HTML format. class ZulipContent extends ContentNode implements ZulipMessageContent { - const ZulipContent({super.debugHtmlNode, required this.nodes}); + const ZulipContent({super.debugHtmlNode, required this.nodes, required this.isRTL}); final List nodes; + final bool isRTL; @override List debugDescribeChildren() { @@ -1594,8 +1596,9 @@ class _ZulipContentParser { ZulipContent parse(String html) { final fragment = HtmlParser(html, parseMeta: false).parseFragment(); + final isRTL = Bidi.detectRtlDirectionality(html, isHtml: true); final nodes = parseBlockContentList(fragment.nodes); - return ZulipContent(nodes: nodes, debugHtmlNode: kDebugMode ? fragment : null); + return ZulipContent(nodes: nodes, debugHtmlNode: kDebugMode ? fragment : null, isRTL: isRTL); } } diff --git a/lib/widgets/content.dart b/lib/widgets/content.dart index b99fcb30a7..2776d54f52 100644 --- a/lib/widgets/content.dart +++ b/lib/widgets/content.dart @@ -6,7 +6,7 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:html/dom.dart' as dom; -import 'package:intl/intl.dart'; +import 'package:intl/intl.dart' hide TextDirection; import 'package:flutter_gen/gen_l10n/zulip_localizations.dart'; import '../api/core.dart'; @@ -279,7 +279,12 @@ class MessageContent extends StatelessWidget { child: DefaultTextStyle( style: ContentTheme.of(context).textStylePlainParagraph, child: switch (content) { - ZulipContent() => BlockContentList(nodes: content.nodes), + ZulipContent() => + content.isRTL + ? Directionality( + textDirection: TextDirection.rtl, + child: BlockContentList(nodes: content.nodes)) + : BlockContentList(nodes: content.nodes), PollContent() => PollWidget(messageId: message.id, poll: content.poll), })); }