make code blocks copyable
This commit is contained in:
parent
c840c42d94
commit
d541e58621
|
|
@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter_highlighter/flutter_highlighter.dart';
|
import 'package:flutter_highlighter/flutter_highlighter.dart';
|
||||||
import 'package:flutter_highlighter/themes/shades-of-purple.dart';
|
import 'package:flutter_highlighter/themes/shades-of-purple.dart';
|
||||||
|
import 'package:highlight_selectable/theme_map.dart';
|
||||||
|
import 'package:highlight_selectable/highlight_selectable.dart';
|
||||||
import 'package:flutter_linkify/flutter_linkify.dart';
|
import 'package:flutter_linkify/flutter_linkify.dart';
|
||||||
import 'package:html/dom.dart' as dom;
|
import 'package:html/dom.dart' as dom;
|
||||||
import 'package:html/parser.dart' as parser;
|
import 'package:html/parser.dart' as parser;
|
||||||
|
|
@ -272,35 +274,35 @@ class HtmlMessage extends StatelessWidget {
|
||||||
);
|
);
|
||||||
case 'code':
|
case 'code':
|
||||||
final isInline = node.parent?.localName != 'pre';
|
final isInline = node.parent?.localName != 'pre';
|
||||||
return WidgetSpan(
|
return isInline
|
||||||
child: Material(
|
? TextSpan(
|
||||||
clipBehavior: Clip.hardEdge,
|
text: node.text,
|
||||||
borderRadius: BorderRadius.circular(4),
|
style: TextStyle(
|
||||||
child: SingleChildScrollView(
|
fontSize: fontSize,
|
||||||
scrollDirection: Axis.horizontal,
|
fontFamily: 'RobotoMono',
|
||||||
child: SelectableRegion(
|
backgroundColor: const Color(0xff2d2b57),
|
||||||
selectionControls: MaterialTextSelectionControls(),
|
color: const Color(0xffe3dfff),
|
||||||
child: HighlightView(
|
),
|
||||||
|
)
|
||||||
|
: WidgetSpan(
|
||||||
|
child: HighlightSelectable(
|
||||||
node.text,
|
node.text,
|
||||||
language: node.className
|
language: node.className
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.singleWhereOrNull(
|
.singleWhereOrNull(
|
||||||
(className) => className.startsWith('language-'),
|
(className) => className.startsWith('language-'))
|
||||||
)
|
|
||||||
?.split('language-')
|
?.split('language-')
|
||||||
.last ??
|
.last ??
|
||||||
'md',
|
'md',
|
||||||
theme: shadesOfPurpleTheme,
|
theme: themeMap['shades-of-purple']!,
|
||||||
|
selectable: true,
|
||||||
|
showCopyButton: !isInline,
|
||||||
padding: EdgeInsets.symmetric(
|
padding: EdgeInsets.symmetric(
|
||||||
horizontal: 8,
|
horizontal: 8,
|
||||||
vertical: isInline ? 0 : 8,
|
vertical: isInline ? 0 : 8,
|
||||||
),
|
),
|
||||||
textStyle: TextStyle(
|
textStyle:
|
||||||
fontSize: fontSize,
|
TextStyle(fontSize: fontSize, fontFamily: 'RobotoMono'),
|
||||||
fontFamily: 'RobotoMono',
|
|
||||||
),
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
case 'img':
|
case 'img':
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:extera_next/generated/l10n/l10n.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
import 'package:pretty_qr_code/pretty_qr_code.dart';
|
import 'package:pretty_qr_code/pretty_qr_code.dart';
|
||||||
|
|
||||||
import 'package:extera_next/config/app_config.dart';
|
import 'package:extera_next/config/app_config.dart';
|
||||||
import 'package:extera_next/config/themes.dart';
|
import 'package:extera_next/config/themes.dart';
|
||||||
|
import 'package:extera_next/generated/l10n/l10n.dart';
|
||||||
import 'package:extera_next/pages/new_private_chat/new_private_chat.dart';
|
import 'package:extera_next/pages/new_private_chat/new_private_chat.dart';
|
||||||
import 'package:extera_next/utils/localized_exception_extension.dart';
|
import 'package:extera_next/utils/localized_exception_extension.dart';
|
||||||
import 'package:extera_next/utils/platform_infos.dart';
|
import 'package:extera_next/utils/platform_infos.dart';
|
||||||
|
|
@ -99,15 +99,14 @@ class NewPrivateChatView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: AnimatedCrossFade(
|
child: AnimatedSwitcher(
|
||||||
duration: FluffyThemes.animationDuration,
|
duration: FluffyThemes.animationDuration,
|
||||||
crossFadeState: searchResponse == null
|
child: searchResponse == null
|
||||||
? CrossFadeState.showFirst
|
? ListView(
|
||||||
: CrossFadeState.showSecond,
|
|
||||||
firstChild: ListView(
|
|
||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 18.0),
|
padding:
|
||||||
|
const EdgeInsets.symmetric(horizontal: 18.0),
|
||||||
child: SelectableText.rich(
|
child: SelectableText.rich(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
children: [
|
children: [
|
||||||
|
|
@ -124,15 +123,17 @@ class NewPrivateChatView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: theme.colorScheme.onSurface,
|
color: theme.colorScheme.onSurface,
|
||||||
fontSize: 13,
|
fontSize: 12,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: CircleAvatar(
|
leading: CircleAvatar(
|
||||||
backgroundColor: theme.colorScheme.secondaryContainer,
|
backgroundColor:
|
||||||
foregroundColor: theme.colorScheme.onSecondaryContainer,
|
theme.colorScheme.secondaryContainer,
|
||||||
|
foregroundColor:
|
||||||
|
theme.colorScheme.onSecondaryContainer,
|
||||||
child: Icon(Icons.adaptive.share_outlined),
|
child: Icon(Icons.adaptive.share_outlined),
|
||||||
),
|
),
|
||||||
title: Text(L10n.of(context).shareInviteLink),
|
title: Text(L10n.of(context).shareInviteLink),
|
||||||
|
|
@ -140,8 +141,10 @@ class NewPrivateChatView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: CircleAvatar(
|
leading: CircleAvatar(
|
||||||
backgroundColor: theme.colorScheme.tertiaryContainer,
|
backgroundColor:
|
||||||
foregroundColor: theme.colorScheme.onTertiaryContainer,
|
theme.colorScheme.tertiaryContainer,
|
||||||
|
foregroundColor:
|
||||||
|
theme.colorScheme.onTertiaryContainer,
|
||||||
child: const Icon(Icons.group_add_outlined),
|
child: const Icon(Icons.group_add_outlined),
|
||||||
),
|
),
|
||||||
title: Text(L10n.of(context).createGroup),
|
title: Text(L10n.of(context).createGroup),
|
||||||
|
|
@ -150,9 +153,12 @@ class NewPrivateChatView extends StatelessWidget {
|
||||||
if (PlatformInfos.isMobile)
|
if (PlatformInfos.isMobile)
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: CircleAvatar(
|
leading: CircleAvatar(
|
||||||
backgroundColor: theme.colorScheme.primaryContainer,
|
backgroundColor:
|
||||||
foregroundColor: theme.colorScheme.onPrimaryContainer,
|
theme.colorScheme.primaryContainer,
|
||||||
child: const Icon(Icons.qr_code_scanner_outlined),
|
foregroundColor:
|
||||||
|
theme.colorScheme.onPrimaryContainer,
|
||||||
|
child:
|
||||||
|
const Icon(Icons.qr_code_scanner_outlined),
|
||||||
),
|
),
|
||||||
title: Text(L10n.of(context).scanQrCode),
|
title: Text(L10n.of(context).scanQrCode),
|
||||||
onTap: controller.openScannerAction,
|
onTap: controller.openScannerAction,
|
||||||
|
|
@ -164,29 +170,36 @@ class NewPrivateChatView extends StatelessWidget {
|
||||||
vertical: 24.0,
|
vertical: 24.0,
|
||||||
),
|
),
|
||||||
child: Material(
|
child: Material(
|
||||||
borderRadius:
|
shape: RoundedRectangleBorder(
|
||||||
BorderRadius.circular(AppConfig.borderRadius),
|
borderRadius: BorderRadius.circular(
|
||||||
color: theme.colorScheme.primaryContainer,
|
AppConfig.borderRadius,
|
||||||
|
),
|
||||||
|
side: BorderSide(
|
||||||
|
width: 3,
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
color: Colors.transparent,
|
||||||
clipBehavior: Clip.hardEdge,
|
clipBehavior: Clip.hardEdge,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
borderRadius:
|
borderRadius: BorderRadius.circular(
|
||||||
BorderRadius.circular(AppConfig.borderRadius),
|
AppConfig.borderRadius,
|
||||||
|
),
|
||||||
onTap: () => showQrCodeViewer(
|
onTap: () => showQrCodeViewer(
|
||||||
context,
|
context,
|
||||||
userId,
|
userId,
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(32.0),
|
padding: const EdgeInsets.all(16.0),
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints:
|
constraints:
|
||||||
const BoxConstraints(maxWidth: 256),
|
const BoxConstraints(maxWidth: 200),
|
||||||
child: PrettyQrView.data(
|
child: PrettyQrView.data(
|
||||||
data: 'https://matrix.to/#/$userId',
|
data: 'https://matrix.to/#/$userId',
|
||||||
decoration: PrettyQrDecoration(
|
decoration: PrettyQrDecoration(
|
||||||
shape: PrettyQrSmoothSymbol(
|
shape: PrettyQrSmoothSymbol(
|
||||||
roundFactor: 1,
|
roundFactor: 1,
|
||||||
color:
|
color: theme.colorScheme.primary,
|
||||||
theme.colorScheme.onPrimaryContainer,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -197,8 +210,8 @@ class NewPrivateChatView extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
)
|
||||||
secondChild: FutureBuilder(
|
: FutureBuilder(
|
||||||
future: searchResponse,
|
future: searchResponse,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
final result = snapshot.data;
|
final result = snapshot.data;
|
||||||
|
|
|
||||||
|
|
@ -139,19 +139,17 @@ class _MxcImageState extends State<MxcImage> {
|
||||||
final data = _imageData;
|
final data = _imageData;
|
||||||
final hasData = data != null && data.isNotEmpty;
|
final hasData = data != null && data.isNotEmpty;
|
||||||
|
|
||||||
return AnimatedCrossFade(
|
return AnimatedSwitcher(
|
||||||
crossFadeState:
|
|
||||||
hasData ? CrossFadeState.showSecond : CrossFadeState.showFirst,
|
|
||||||
duration: const Duration(milliseconds: 128),
|
duration: const Duration(milliseconds: 128),
|
||||||
firstChild: placeholder(context),
|
child: hasData
|
||||||
secondChild: hasData
|
|
||||||
? Image.memory(
|
? Image.memory(
|
||||||
data,
|
data,
|
||||||
width: widget.width,
|
width: widget.width,
|
||||||
height: widget.height,
|
height: widget.height,
|
||||||
fit: widget.fit,
|
fit: widget.fit,
|
||||||
filterQuality:
|
filterQuality: widget.isThumbnail
|
||||||
widget.isThumbnail ? FilterQuality.low : FilterQuality.medium,
|
? FilterQuality.low
|
||||||
|
: FilterQuality.medium,
|
||||||
errorBuilder: (context, e, s) {
|
errorBuilder: (context, e, s) {
|
||||||
Logs().d('Unable to render mxc image', e, s);
|
Logs().d('Unable to render mxc image', e, s);
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
|
|
@ -168,10 +166,6 @@ class _MxcImageState extends State<MxcImage> {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
: SizedBox(
|
: placeholder(context));
|
||||||
width: widget.width,
|
|
||||||
height: widget.height,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
20
pubspec.lock
20
pubspec.lock
|
|
@ -849,6 +849,22 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.4.0"
|
version: "0.4.0"
|
||||||
|
highlight:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: highlight
|
||||||
|
sha256: "5353a83ffe3e3eca7df0abfb72dcf3fa66cc56b953728e7113ad4ad88497cf21"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.7.0"
|
||||||
|
highlight_selectable:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: highlight_selectable
|
||||||
|
sha256: c9a9c8741bd5ba2150f1ba2c713f4ea2d6dfd6b700d66ca11675882a75c4db20
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "0.1.4"
|
||||||
highlighter:
|
highlighter:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -1170,10 +1186,10 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: matrix
|
name: matrix
|
||||||
sha256: "0c033a6ebf4ed2f56ed604769984072961fefc0cb255a802ed441dcaec490196"
|
sha256: "4e6c186115ee041c430aa5ed5210499d60e4323f907cea1f5e8a2f73a513a1bf"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.1.0"
|
version: "1.1.1"
|
||||||
meta:
|
meta:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ dependencies:
|
||||||
desktop_notifications: ^0.6.3
|
desktop_notifications: ^0.6.3
|
||||||
device_info_plus: ^10.0.1
|
device_info_plus: ^10.0.1
|
||||||
dynamic_color: ^1.8.1
|
dynamic_color: ^1.8.1
|
||||||
|
highlight_selectable: ^0.1.0
|
||||||
emoji_picker_flutter: ^3.1.0
|
emoji_picker_flutter: ^3.1.0
|
||||||
emojis: ^0.9.9
|
emojis: ^0.9.9
|
||||||
#fcm_shared_isolate: ^0.2.0
|
#fcm_shared_isolate: ^0.2.0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue