Skip to content

Commit 2ae0053

Browse files
committed
revert(html): revert experimental selectable contents
This reverts commit 45844a3. Reasons to revert: * For full text selectable readonly editor contents, `SelectableText` only works on `TextSpan` children. `WidgetSpan` will make a gap for text selection and implementing a `SelectableWidgetSpan` combines both kinds of span is not easy to do: assert failure everywhere. * `SelectableArea` handles `onTap` event where we only want the gesture passed to children so that users could activate reply state by a single tap, to fix the issue we need a custom ignore pointer widget. * Rendered style not consists comparing the editor when editing and viewing page contents because the later one uses custom html parser while the former one uses editor which renders custom bbcode tags, they are not the same, both in history and in the future, as long as the process differs. And the html parser is quite limited and not stable, endless html layout rules are not clearly implemented, especially in line break. Frequently used layout are supported but not always be, massive special logic in the custom html parser makes it hard to maintain, let alone the selectable text feature we want to land in a future version. I think it's time to sunset the current html parser, or at least render into quill_delta so that we can have consistent contents appearance when editing and viewing contents. Next step: * Other implementation may not work, like use `Wrap` to simulate the original rich text features in flutter SDK, I don't think the result could be better than the one in SDK. * We need selectable text and consistent appearance when editing and viewing contents so render it in the bbcode editor is the best choice. Waiting for upstream fix selection in readOnly mode here: singerdmx/flutter-quill#2529 After that, parse supported tags here: https://github.com/realth000/tsdm_client/blob/81395ca8f5f5ee9ebe63cff1d223f585a895bf9a/lib/utils/html/html_muncher.dart#L335 into custom bbcode tags to let the bbcode editor render it as common quill_delta tags, hard but worth it.
1 parent 81395ca commit 2ae0053

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

lib/utils/html/html_muncher.dart

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Widget munchElement(
7777
// Currently is 712.
7878
return ConstrainedBox(
7979
constraints: const BoxConstraints(maxWidth: htmlContentMaxWidth),
80-
child: SelectableText.rich(TextSpan(children: ret)),
80+
child: Text.rich(TextSpan(children: ret)),
8181
);
8282
}
8383

@@ -485,9 +485,7 @@ final class _Muncher with LoggerMixin {
485485

486486
if (align != null) {
487487
ret2 = [
488-
WidgetSpan(
489-
child: Row(children: [Expanded(child: SelectableText.rich(TextSpan(children: ret), textAlign: align))]),
490-
),
488+
WidgetSpan(child: Row(children: [Expanded(child: Text.rich(TextSpan(children: ret), textAlign: align))])),
491489
];
492490

493491
// Restore text align.
@@ -777,7 +775,7 @@ final class _Muncher with LoggerMixin {
777775
// Text already has the label, do not add duplicate one.
778776
content = null;
779777
} else {
780-
content = SelectableText('@', style: TextStyle(color: Theme.of(context).colorScheme.primary));
778+
content = Text('@', style: TextStyle(color: Theme.of(context).colorScheme.primary));
781779
}
782780
} else {
783781
final IconData prefixIcon;
@@ -933,7 +931,7 @@ final class _Muncher with LoggerMixin {
933931
color: Theme.of(context).colorScheme.onSecondary,
934932
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(5))),
935933
margin: EdgeInsets.zero,
936-
child: SelectableText.rich(TextSpan(children: ret)),
934+
child: Text.rich(TextSpan(children: ret)),
937935
),
938936
);
939937
state.elevation -= _elevationStep;
@@ -1079,7 +1077,7 @@ final class _Muncher with LoggerMixin {
10791077
final tableRowContent = <Widget>[];
10801078
final tds = tr.querySelectorRootAll('td');
10811079
for (final td in tds) {
1082-
tableRowContent.add(SelectableText.rich(TextSpan(children: _buildTd(td))));
1080+
tableRowContent.add(Text.rich(TextSpan(children: _buildTd(td))));
10831081
}
10841082
if (tds.length > columnMaxCount) {
10851083
columnMaxCount = tds.length;

lib/widgets/quoted_text.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class QuotedText extends StatelessWidget {
3434
final spanTail = TextSpan(children: [WidgetSpan(child: iconTail)]);
3535

3636
if (text != null) {
37-
return SelectableText.rich(TextSpan(children: [spanHead, TextSpan(text: ' $text '), spanTail]));
37+
return Text.rich(TextSpan(children: [spanHead, TextSpan(text: ' $text '), spanTail]));
3838
}
3939

4040
if (span != null) {
@@ -45,10 +45,10 @@ class QuotedText extends StatelessWidget {
4545
return Row(
4646
crossAxisAlignment: CrossAxisAlignment.start,
4747
children: [
48-
SelectableText.rich(TextSpan(children: [WidgetSpan(child: Align(child: iconHead))])),
48+
Text.rich(WidgetSpan(child: Align(child: iconHead))),
4949
sizedBoxW4H4,
5050
Expanded(
51-
child: SelectableText.rich(
51+
child: Text.rich(
5252
TextSpan(
5353
children: [
5454
// Add a line feed to ensure the child content is lower than

0 commit comments

Comments
 (0)