diff --git a/lib/core/utils/text_format.dart b/lib/core/utils/text_format.dart index a321c45..79b94ca 100644 --- a/lib/core/utils/text_format.dart +++ b/lib/core/utils/text_format.dart @@ -158,47 +158,29 @@ List segmentizeFormats(String text, List ranges) { TextStyle applyTextFormats( TextStyle base, Set formats, { - Color? linkColor, Color? quoteColor, - Color? monoColor, }) { if (formats.isEmpty) return base; - var style = base; - final decorations = []; - if (formats.contains(TextFormat.strong)) { - style = style.merge(const TextStyle(fontWeight: FontWeight.w700)); - } - if (formats.contains(TextFormat.emphasized) || - formats.contains(TextFormat.quote)) { - style = style.merge(const TextStyle(fontStyle: FontStyle.italic)); - } - if (formats.contains(TextFormat.monospaced)) { - style = style.merge( - TextStyle( - fontFamily: 'monospace', - color: monoColor ?? style.color, - ), - ); - } - if (formats.contains(TextFormat.quote) && quoteColor != null) { - style = style.merge(TextStyle(color: quoteColor)); - } - if (formats.contains(TextFormat.underline)) { + final decorations = []; + if (formats.contains(TextFormat.underline) || + formats.contains(TextFormat.link)) { decorations.add(TextDecoration.underline); } if (formats.contains(TextFormat.strikethrough)) { decorations.add(TextDecoration.lineThrough); } - if (formats.contains(TextFormat.link)) { - decorations.add(TextDecoration.underline); - if (linkColor != null) style = style.merge(TextStyle(color: linkColor)); - } - if (decorations.isNotEmpty) { - style = style.merge( - TextStyle(decoration: TextDecoration.combine(decorations)), - ); - } - return style; + final isItalic = formats.contains(TextFormat.emphasized) || + formats.contains(TextFormat.quote); + + return base.copyWith( + fontWeight: formats.contains(TextFormat.strong) ? FontWeight.w700 : null, + fontStyle: isItalic ? FontStyle.italic : null, + fontFamily: formats.contains(TextFormat.monospaced) ? 'monospace' : null, + color: formats.contains(TextFormat.quote) ? quoteColor : null, + decoration: decorations.isEmpty + ? null + : TextDecoration.combine(decorations), + ); } diff --git a/lib/frontend/screens/chats/chat_list_screen.dart b/lib/frontend/screens/chats/chat_list_screen.dart index c3148dd..0a91e96 100644 --- a/lib/frontend/screens/chats/chat_list_screen.dart +++ b/lib/frontend/screens/chats/chat_list_screen.dart @@ -2221,6 +2221,53 @@ class _ChatListScreenState extends State ); } + Widget _buildPreviewLine( + ColorScheme cs, + String message, + List messageRanges, + String? draft, + bool messageItalic, + ) { + if (draft != null) { + return Text.rich( + TextSpan( + children: [ + TextSpan(text: 'Черновик: ', style: TextStyle(color: cs.error)), + TextSpan(text: draft, style: TextStyle(color: cs.outline)), + ], + style: const TextStyle( + fontSize: 14, + fontWeight: FontWeight.w400, + fontStyle: FontStyle.italic, + height: 1.2, + ), + ), + maxLines: 1, + overflow: TextOverflow.ellipsis, + ); + } + final previewStyle = TextStyle( + color: cs.outline, + fontSize: 14, + fontWeight: FontWeight.w400, + fontStyle: messageItalic ? FontStyle.italic : FontStyle.normal, + height: 1.2, + ); + if (messageRanges.isEmpty) { + return Text( + message, + style: previewStyle, + maxLines: 1, + overflow: TextOverflow.ellipsis, + ); + } + return Text.rich( + FormattedMessageText.buildInlineSpan(message, messageRanges, previewStyle), + maxLines: 1, + overflow: TextOverflow.ellipsis, + ); + } + Widget _buildChatItem( String id, String name, @@ -2245,6 +2292,13 @@ class _ChatListScreenState extends State final Widget? statusIcon = (ownStatus != null && draft == null) ? _ownStatusIcon(cs, ownStatus, ownRead) : null; + final Widget messageLine = _buildPreviewLine( + cs, + message, + messageRanges, + draft, + messageItalic, + ); return InkWell( key: ValueKey('chat_$id'), @@ -2425,61 +2479,7 @@ class _ChatListScreenState extends State Expanded( child: _ActivitySubtitle( chatId: int.tryParse(id) ?? 0, - child: draft != null - ? Text.rich( - TextSpan( - children: [ - TextSpan( - text: 'Черновик: ', - style: TextStyle(color: cs.error), - ), - TextSpan( - text: draft, - style: TextStyle( - color: cs.outline, - ), - ), - ], - style: const TextStyle( - fontSize: 14, - fontWeight: FontWeight.w400, - fontStyle: FontStyle.italic, - height: 1.2, - ), - ), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ) - : Builder( - builder: (_) { - final previewStyle = TextStyle( - color: cs.outline, - fontSize: 14, - fontWeight: FontWeight.w400, - fontStyle: messageItalic - ? FontStyle.italic - : FontStyle.normal, - height: 1.2, - ); - if (messageRanges.isEmpty) { - return Text( - message, - style: previewStyle, - maxLines: 1, - overflow: TextOverflow.ellipsis, - ); - } - return Text.rich( - FormattedMessageText.buildInlineSpan( - message, - messageRanges, - previewStyle, - ), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ); - }, - ), + child: messageLine, ), ), ?statusIcon,