mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: unable to cancel the inline math equation format (#2974)
* fix: unable to cancel the inline math equation format * fix: bold font style used in the document is not suitable * chore: add flutter clean before executing the release task * fix: integration test
This commit is contained in:
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
},
|
||||
);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user