Skip to content

Commit 925cb6b

Browse files
committed
fix(*): temporary fallback to raw code on spoiler and hide embeds
Spoiler and hide embeds are causing extream junk on Android, the root cause seems live deep in flutter_quill or flutter itself, maybe because of the page pushing/popping or the nested editor makes some Android native components confusing on the IME state. This issue was introduced ever since those two tags are landed. Now sometimes it does not cause junk but in the background log same messages still here so it's hard to figure out which user action directly caused it. Though a new implementation of direct access on these two tags is on the way, process still lives in early stage and the junk it caused worth a temporary fix. This commit made the functionality fallback to raw code mode on Android. ref: realth000/tsdm_client#134
1 parent 2eea38c commit 925cb6b

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/src/editor_controller.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ extension BBCodeExt on BBCodeEditorController {
8383
..moveCursorToPosition(index + text.length);
8484
}
8585

86+
/// Insert raw bbcode that has a [head] and [tail] and move cursor to the
87+
/// position between them after insertion.
88+
void insertRawCode(String head, String tail) {
89+
this
90+
..replaceText(index, length, head + tail, null)
91+
..editorFocusNode?.requestFocus()
92+
..moveCursorToPosition(index + head.length);
93+
}
94+
8695
/// Insert formatted embed block [embed] into editor.
8796
void insertEmbedBlock(CustomBlockEmbed embed) {
8897
this

lib/src/tags/hide/hide_buttton.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:io';
2+
13
import 'package:flutter/material.dart';
24
import 'package:flutter_bbcode_editor/flutter_bbcode_editor.dart';
35
import 'package:flutter_bbcode_editor/src/editor.dart';
@@ -24,6 +26,10 @@ class BBCodeEditorToolbarHideButton extends StatelessWidget {
2426
iconTheme: context.quillToolbarBaseButtonOptions?.iconTheme,
2527
isSelected: false,
2628
onPressed: () async {
29+
if (Platform.isAndroid) {
30+
controller.insertRawCode('[hide]', '[/hide]');
31+
return;
32+
}
2733
controller
2834
.insertEmbeddable(BBCodeHideEmbed(BBCodeHideInfo.buildEmpty()));
2935
},

lib/src/tags/spoiler/spoiler_button.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:io';
2+
13
import 'package:flutter/material.dart';
24
import 'package:flutter_bbcode_editor/flutter_bbcode_editor.dart';
35
import 'package:flutter_bbcode_editor/src/editor.dart';
@@ -24,6 +26,13 @@ class BBCodeEditorToolbarSpoilerButton extends StatelessWidget {
2426
iconTheme: context.quillToolbarBaseButtonOptions?.iconTheme,
2527
isSelected: false,
2628
onPressed: () async {
29+
if (Platform.isAndroid) {
30+
controller.insertRawCode(
31+
'[spoiler=${context.bbcodeL10n.spoilerExpandOrCollapse}]',
32+
'[/spoiler]',
33+
);
34+
return;
35+
}
2736
controller.insertEmbeddable(
2837
BBCodeSpoilerEmbed(
2938
BBCodeSpoilerInfo.buildEmpty(

0 commit comments

Comments
 (0)