оптимизация не дремлет
This commit is contained in:
@@ -158,47 +158,29 @@ List<FormatSegment> segmentizeFormats(String text, List<FormatRange> ranges) {
|
||||
TextStyle applyTextFormats(
|
||||
TextStyle base,
|
||||
Set<TextFormat> formats, {
|
||||
Color? linkColor,
|
||||
Color? quoteColor,
|
||||
Color? monoColor,
|
||||
}) {
|
||||
if (formats.isEmpty) return base;
|
||||
var style = base;
|
||||
final decorations = <TextDecoration>[];
|
||||
|
||||
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 = <TextDecoration>[];
|
||||
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),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2221,6 +2221,53 @@ class _ChatListScreenState extends State<ChatListScreen>
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPreviewLine(
|
||||
ColorScheme cs,
|
||||
String message,
|
||||
List<FormatRange> 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<ChatListScreen>
|
||||
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<ChatListScreen>
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user