Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: unable to cancel the inline math equation format (#2974)

Lucas.Xub9976b072ed2
diff --git a/frontend/appflowy_flutter/integration_test/document/document_with_inline_math_equation_test.dart b/frontend/appflowy_flutter/integration_test/document/document_with_inline_math_equation_test.dart
index 00f791cfbb..dd65843f21 100644
--- a/frontend/appflowy_flutter/integration_test/document/document_with_inline_math_equation_test.dart
+++ b/frontend/appflowy_flutter/integration_test/document/document_with_inline_math_equation_test.dart
@@ -61,5 +61,61 @@ void main() {
);
await tester.pumpAndSettle();
});
+
+ testWidgets('remove the inline math equation format', (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapGoButton();
+
+ // create a new document
+ await tester.createNewPageWithName(
+ ViewLayoutPB.Document,
+ LocaleKeys.document_plugins_createInlineMathEquation.tr(),
+ );
+
+ // tap the first line of the document
+ await tester.editor.tapLineOfEditorAt(0);
+ // insert a inline page
+ const formula = 'E = MC ^ 2';
+ await tester.ime.insertText(formula);
+ await tester.editor.updateSelection(
+ Selection.single(path: [0], startOffset: 0, endOffset: formula.length),
+ );
+
+ // tap the inline math equation button
+ var inlineMathEquationButton = find.byTooltip(
+ LocaleKeys.document_plugins_createInlineMathEquation.tr(),
+ );
+ await tester.tapButton(inlineMathEquationButton);
+
+ // expect to see the math equation block
+ var inlineMathEquation = find.byType(InlineMathEquation);
+ expect(inlineMathEquation, findsOneWidget);
+
+ // highlight the math equation block
+ await tester.editor.updateSelection(
+ Selection.single(path: [0], startOffset: 0, endOffset: 1),
+ );
+
+ // expect to the see the inline math equation button is highlighted
+ inlineMathEquationButton = find.byWidgetPredicate(
+ (widget) =>
+ widget is IconItemWidget &&
+ widget.tooltip ==
+ LocaleKeys.document_plugins_createInlineMathEquation.tr(),
+ );
+ expect(
+ tester.widget<IconItemWidget>(inlineMathEquationButton).isHighlight,
+ isTrue,
+ );
+
+ // cancel the format
+ await tester.tapButton(inlineMathEquationButton);
+
+ // expect to see the math equation block is removed
+ inlineMathEquation = find.byType(InlineMathEquation);
+ expect(inlineMathEquation, findsNothing);
+
+ tester.expectToSeeText(formula);
+ });
});
}
diff --git a/frontend/appflowy_flutter/integration_test/open_ai_smart_menu_test.dart b/frontend/appflowy_flutter/integration_test/open_ai_smart_menu_test.dart
index 75c9834ee8..98c0378f59 100644
--- a/frontend/appflowy_flutter/integration_test/open_ai_smart_menu_test.dart
+++ b/frontend/appflowy_flutter/integration_test/open_ai_smart_menu_test.dart
@@ -17,7 +17,8 @@ void main() {
setUpAll(() async => await service.setUpAll());
setUp(() async => await service.setUp());
- testWidgets('testing selection on open-ai smart menu replace', (tester) async {
+ testWidgets('testing selection on open-ai smart menu replace',
+ (tester) async {
final appFlowyEditor = await setUpOpenAITesting(tester);
final editorState = appFlowyEditor.editorState;
@@ -38,7 +39,8 @@ void main() {
await tester.tap(find.text('Summarize'));
await tester.pumpAndSettle();
- await tester.tap(find.byType(FlowyRichTextButton, skipOffstage: false).first);
+ await tester
+ .tap(find.byType(FlowyRichTextButton, skipOffstage: false).first);
await tester.pumpAndSettle();
expect(
@@ -49,7 +51,8 @@ void main() {
),
);
});
- testWidgets('testing selection on open-ai smart menu insert', (tester) async {
+ testWidgets('testing selection on open-ai smart menu insert',
+ (tester) async {
final appFlowyEditor = await setUpOpenAITesting(tester);
final editorState = appFlowyEditor.editorState;
@@ -69,7 +72,8 @@ void main() {
await tester.tap(find.text('Summarize'));
await tester.pumpAndSettle();
- await tester.tap(find.byType(FlowyRichTextButton, skipOffstage: false).at(1));
+ await tester
+ .tap(find.byType(FlowyRichTextButton, skipOffstage: false).at(1));
await tester.pumpAndSettle();
expect(
diff --git a/frontend/appflowy_flutter/integration_test/util/editor_test_operations.dart b/frontend/appflowy_flutter/integration_test/util/editor_test_operations.dart
index cb015709cc..1269c4a511 100644
--- a/frontend/appflowy_flutter/integration_test/util/editor_test_operations.dart
+++ b/frontend/appflowy_flutter/integration_test/util/editor_test_operations.dart
@@ -32,7 +32,7 @@ class EditorOperations {
/// Tap the line of editor at [index]
Future<void> tapLineOfEditorAt(int index) async {
- final textBlocks = find.byType(FlowyRichText);
+ final textBlocks = find.byType(AppFlowyRichText);
index = index.clamp(0, textBlocks.evaluate().length - 1);
await tester.tapAt(tester.getTopRight(textBlocks.at(index)));
await tester.pumpAndSettle();
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
index f30063be9b..efd2d8579d 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
@@ -126,7 +126,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
final (bool autoFocus, Selection? selection) =
_computeAutoFocusParameters();
- final editor = AppFlowyEditor.custom(
+ final editor = AppFlowyEditor(
editorState: widget.editorState,
editable: true,
shrinkWrap: widget.shrinkWrap,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart
index 2e6b63fe5b..045f8c6ed4 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart
@@ -105,7 +105,7 @@ class CalloutBlockComponentWidget extends BlockComponentStatefulWidget {
class _CalloutBlockComponentWidgetState
extends State<CalloutBlockComponentWidget>
- with SelectableMixin, DefaultSelectable, BlockComponentConfigurable {
+ with SelectableMixin, DefaultSelectableMixin, BlockComponentConfigurable {
// the key used to forward focus to the richtext child
@override
final forwardKey = GlobalKey(debugLabel: 'flowy_rich_text');
@@ -192,7 +192,7 @@ class _CalloutBlockComponentWidgetState
Widget buildCalloutBlockComponent(BuildContext context) {
return Padding(
padding: padding,
- child: FlowyRichText(
+ child: AppFlowyRichText(
key: forwardKey,
node: widget.node,
editorState: editorState,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart
index c4731499ea..85c6a88679 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_component.dart
@@ -96,7 +96,7 @@ class CodeBlockComponentWidget extends BlockComponentStatefulWidget {
}
class _CodeBlockComponentWidgetState extends State<CodeBlockComponentWidget>
- with SelectableMixin, DefaultSelectable, BlockComponentConfigurable {
+ with SelectableMixin, DefaultSelectableMixin, BlockComponentConfigurable {
// the key used to forward focus to the richtext child
@override
final forwardKey = GlobalKey(debugLabel: 'flowy_rich_text');
@@ -216,7 +216,7 @@ class _CodeBlockComponentWidgetState extends State<CodeBlockComponentWidget>
final codeTextSpans = _convert(codeNodes);
return Padding(
padding: widget.padding,
- child: FlowyRichText(
+ child: AppFlowyRichText(
key: forwardKey,
node: widget.node,
editorState: editorState,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/inline_math_equation/inline_math_equation_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/inline_math_equation/inline_math_equation_toolbar_item.dart
index 7df4d49385..77871450bf 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/inline_math_equation/inline_math_equation_toolbar_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/inline_math_equation/inline_math_equation_toolbar_item.dart
@@ -21,7 +21,7 @@ final ToolbarItem inlineMathEquationItem = ToolbarItem(
iconBuilder: (_) => svgWidget(
'editor/math',
size: const Size.square(16),
- color: Colors.white,
+ color: isHighlight ? Colors.lightBlue : Colors.white,
),
isHighlight: isHighlight,
tooltip: LocaleKeys.document_plugins_createInlineMathEquation.tr(),
@@ -31,12 +31,33 @@ final ToolbarItem inlineMathEquationItem = ToolbarItem(
return;
}
final node = editorState.getNodeAtPath(selection.start.path);
- if (node == null) {
+ final delta = node?.delta;
+ if (node == null || delta == null) {
return;
}
- final text = editorState.getTextInSelection(selection).join();
- final transaction = editorState.transaction
- ..replaceText(
+
+ final transaction = editorState.transaction;
+ if (isHighlight) {
+ final formula = delta
+ .slice(selection.startIndex, selection.endIndex)
+ .whereType<TextInsert>()
+ .firstOrNull
+ ?.attributes?[InlineMathEquationKeys.formula];
+ assert(formula != null);
+ if (formula == null) {
+ return;
+ }
+ // clear the format
+ transaction.replaceText(
+ node,
+ selection.startIndex,
+ selection.length,
+ formula,
+ attributes: {},
+ );
+ } else {
+ final text = editorState.getTextInSelection(selection).join();
+ transaction.replaceText(
node,
selection.startIndex,
selection.length,
@@ -45,6 +66,7 @@ final ToolbarItem inlineMathEquationItem = ToolbarItem(
InlineMathEquationKeys.formula: text,
},
);
+ }
await editorState.apply(transaction);
},
);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart
index d0337dd5e3..d0b4609859 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart
@@ -32,7 +32,7 @@ class MentionPageBlock extends StatefulWidget {
class _MentionPageBlockState extends State<MentionPageBlock> {
late final EditorState editorState;
- late final Future<ViewPB?> viewPBFuture;
+ late Future<ViewPB?> viewPBFuture;
ViewListener? viewListener;
@override
@@ -45,6 +45,7 @@ class _MentionPageBlockState extends State<MentionPageBlock> {
..start(
onViewUpdated: (p0) {
pageMemorizer[p0.id] = p0;
+ viewPBFuture = fetchView(widget.pageId);
editorState.reload();
},
);
@@ -111,11 +112,10 @@ class _MentionPageBlockState extends State<MentionPageBlock> {
}
Future<ViewPB?> fetchView(String pageId) async {
- final views = await ViewBackendService().fetchViews((_, __) => true);
- final flattenViews = views.expand((e) => [e.$1, ...e.$2]).toList();
- final view = flattenViews.firstWhereOrNull(
- (element) => element.id == pageId,
+ final view = await ViewBackendService.getView(pageId).then(
+ (value) => value.swap().toOption().toNullable(),
);
+
if (view == null) {
// try to fetch from trash
final trashViews = await TrashService().readTrash();
@@ -129,6 +129,7 @@ class _MentionPageBlockState extends State<MentionPageBlock> {
..name = trash.name;
}
}
+
return view;
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/migration/editor_migration.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/migration/editor_migration.dart
index 3918a2891e..0cdf04a7d0 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/migration/editor_migration.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/migration/editor_migration.dart
@@ -141,13 +141,13 @@ class EditorMigration {
}
const backgroundColor = 'backgroundColor';
if (attributes.containsKey(backgroundColor)) {
- attributes[FlowyRichTextKeys.highlightColor] =
+ attributes[AppFlowyRichTextKeys.highlightColor] =
attributes[backgroundColor];
attributes.remove(backgroundColor);
}
const color = 'color';
if (attributes.containsKey(color)) {
- attributes[FlowyRichTextKeys.textColor] = attributes[color];
+ attributes[AppFlowyRichTextKeys.textColor] = attributes[color];
attributes.remove(color);
}
return attributes;
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart
index dc1e6be586..a55164dc9c 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/smart_edit_node_widget.dart
@@ -157,7 +157,7 @@ class _SmartEditBlockComponentWidgetState
var width = double.infinity;
final editorSize = editorState.renderBox?.size;
final padding = editorState.editorStyle.padding;
- if (editorSize != null && padding != null) {
+ if (editorSize != null) {
width = editorSize.width - padding.left - padding.right;
}
return width;
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart
index b356f1545c..1889e97311 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart
@@ -84,7 +84,7 @@ class _ToggleListBlockComponentWidgetState
extends State<ToggleListBlockComponentWidget>
with
SelectableMixin,
- DefaultSelectable,
+ DefaultSelectableMixin,
BlockComponentConfigurable,
BackgroundColorMixin {
// the key used to forward focus to the richtext child
@@ -141,7 +141,7 @@ class _ToggleListBlockComponentWidgetState
width: 4.0,
),
Expanded(
- child: FlowyRichText(
+ child: AppFlowyRichText(
key: forwardKey,
node: widget.node,
editorState: editorState,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
index 12895a3e1d..0eb7b7da23 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
@@ -40,15 +40,18 @@ class EditorStyleCustomizer {
color: theme.colorScheme.onBackground,
height: 1.5,
),
- bold: baseTextStyle(fontFamily).copyWith(
+ bold: baseTextStyle(fontFamily, fontWeight: FontWeight.bold).copyWith(
fontWeight: FontWeight.w600,
),
- italic: baseTextStyle(fontFamily).copyWith(fontStyle: FontStyle.italic),
- underline: baseTextStyle(fontFamily)
- .copyWith(decoration: TextDecoration.underline),
- strikethrough:
- baseTextStyle(fontFamily)
- .copyWith(decoration: TextDecoration.lineThrough),
+ italic: baseTextStyle(fontFamily).copyWith(
+ fontStyle: FontStyle.italic,
+ ),
+ underline: baseTextStyle(fontFamily).copyWith(
+ decoration: TextDecoration.underline,
+ ),
+ strikethrough: baseTextStyle(fontFamily).copyWith(
+ decoration: TextDecoration.lineThrough,
+ ),
href: baseTextStyle(fontFamily).copyWith(
color: theme.colorScheme.primary,
decoration: TextDecoration.underline,
@@ -87,8 +90,7 @@ class EditorStyleCustomizer {
italic: baseTextStyle(fontFamily).copyWith(fontStyle: FontStyle.italic),
underline: baseTextStyle(fontFamily)
.copyWith(decoration: TextDecoration.underline),
- strikethrough:
- baseTextStyle(fontFamily)
+ strikethrough: baseTextStyle(fontFamily)
.copyWith(decoration: TextDecoration.lineThrough),
href: baseTextStyle(fontFamily).copyWith(
color: theme.colorScheme.primary,
@@ -163,10 +165,14 @@ class EditorStyleCustomizer {
);
}
- TextStyle baseTextStyle(String fontFamily) {
+ TextStyle baseTextStyle(
+ String fontFamily, {
+ FontWeight? fontWeight,
+ }) {
try {
return GoogleFonts.getFont(
fontFamily,
+ fontWeight: fontWeight,
);
} on Exception {
return GoogleFonts.getFont('Poppins');
@@ -174,6 +180,7 @@ class EditorStyleCustomizer {
}
InlineSpan customizeAttributeDecorator(
+ BuildContext context,
Node node,
int index,
TextInsert text,
diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lock
index 39c56c42a2..799fbc4149 100644
--- a/frontend/appflowy_flutter/pubspec.lock
+++ b/frontend/appflowy_flutter/pubspec.lock
@@ -53,8 +53,8 @@ packages:
dependency: "direct main"
description:
path: "."
- ref: c5b5e64
- resolved-ref: c5b5e641fe11ae634f02db112e71f40a119e9c44
+ ref: "35394cd"
+ resolved-ref: "35394cd4f45f3f98afbec8d23d12fe0bf3cd3f6d"
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
source: git
version: "1.1.0"
diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yaml
index 2962dced30..97f024c5fc 100644
--- a/frontend/appflowy_flutter/pubspec.yaml
+++ b/frontend/appflowy_flutter/pubspec.yaml
@@ -46,7 +46,7 @@ dependencies:
appflowy_editor:
git:
url: https://github.com/AppFlowy-IO/appflowy-editor.git
- ref: c5b5e64
+ ref: 35394cd
appflowy_popover:
path: packages/appflowy_popover
diff --git a/frontend/scripts/makefile/flutter.toml b/frontend/scripts/makefile/flutter.toml
index a2e3646536..d72e4db393 100644
--- a/frontend/scripts/makefile/flutter.toml
+++ b/frontend/scripts/makefile/flutter.toml
@@ -184,6 +184,10 @@ script_runner = "@duckscript"
script_runner = "@shell"
script = [
"""
+ cd appflowy_flutter
+ flutter clean
+ flutter pub get
+ cd ../
sh scripts/code_generation/generate.sh
"""
]
@@ -192,11 +196,14 @@ script = [
script_runner = "@duckscript"
script = [
"""
+ cd ./appflowy_flutter/
+ exec cmd.exe /c flutter clean
+ exec cmd.exe /c flutter pub get
+ cd ../
exec scripts/code_generation/generate.cmd
""",
]
-
[tasks.dry_code_generation]
script_runner = "@shell"
script = [