Skip to content

Commit 690a374

Browse files
authored
feat: optimize the align toolbar item (#4364)
1 parent cd82c13 commit 690a374

File tree

9 files changed

+27
-81
lines changed

9 files changed

+27
-81
lines changed

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/_align_items.dart

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,43 @@ const _center = 'center';
1313
const _right = 'right';
1414

1515
class AlignItems extends StatelessWidget {
16-
const AlignItems({
16+
AlignItems({
1717
super.key,
1818
required this.editorState,
1919
});
2020

2121
final EditorState editorState;
22+
final List<(String, FlowySvgData)> _alignMenuItems = [
23+
(_left, FlowySvgs.m_aa_align_left_s),
24+
(_center, FlowySvgs.m_aa_align_center_s),
25+
(_right, FlowySvgs.m_aa_align_right_s),
26+
];
2227

2328
@override
2429
Widget build(BuildContext context) {
2530
final currentAlignItem = _getCurrentAlignItem();
26-
final alignMenuItems = _getAlignMenuItems();
2731
final theme = ToolbarColorExtension.of(context);
2832
return PopupMenu(
29-
itemLength: alignMenuItems.length,
33+
itemLength: _alignMenuItems.length,
3034
onSelected: (index) {
3135
editorState.alignBlock(
32-
alignMenuItems[index].$1,
36+
_alignMenuItems[index].$1,
3337
selectionExtraInfo: {
3438
selectionExtraInfoDoNotAttachTextService: true,
3539
selectionExtraInfoDisableFloatingToolbar: true,
3640
},
3741
);
3842
},
3943
menuBuilder: (context, keys, currentIndex) {
40-
final children = alignMenuItems
44+
final children = _alignMenuItems
4145
.mapIndexed(
4246
(index, e) => [
4347
PopupMenuItemWrapper(
4448
key: keys[index],
4549
isSelected: currentIndex == index,
4650
icon: e.$2,
4751
),
48-
if (index != 0 && index != alignMenuItems.length - 1)
52+
if (index != 0 && index != _alignMenuItems.length - 1)
4953
const HSpace(12),
5054
],
5155
)
@@ -84,36 +88,12 @@ class AlignItems extends StatelessWidget {
8488
(String, FlowySvgData) _getCurrentAlignItem() {
8589
final align = _getCurrentBlockAlign();
8690
if (align == _center) {
87-
return (_center, FlowySvgs.m_aa_align_center_s);
88-
} else if (align == _right) {
8991
return (_right, FlowySvgs.m_aa_align_right_s);
92+
} else if (align == _right) {
93+
return (_left, FlowySvgs.m_aa_align_left_s);
94+
} else {
95+
return (_center, FlowySvgs.m_aa_align_center_s);
9096
}
91-
return (_left, FlowySvgs.m_aa_align_left_s);
92-
}
93-
94-
List<(String, FlowySvgData)> _getAlignMenuItems() {
95-
return [
96-
(_left, FlowySvgs.m_aa_align_left_s),
97-
(_center, FlowySvgs.m_aa_align_center_s),
98-
(_right, FlowySvgs.m_aa_align_right_s),
99-
];
100-
// final align = _getCurrentBlockAlign();
101-
102-
// if (align == _center) {
103-
// return [
104-
// (_left, FlowySvgs.m_aa_align_left_s),
105-
// (_right, FlowySvgs.m_aa_align_right_s),
106-
// ];
107-
// } else if (align == _right) {
108-
// return [
109-
// (_left, FlowySvgs.m_aa_align_left_s),
110-
// (_center, FlowySvgs.m_aa_align_center_s),
111-
// ];
112-
// }
113-
// return [
114-
// (_center, FlowySvgs.m_aa_align_center_s),
115-
// (_right, FlowySvgs.m_aa_align_right_s),
116-
// ];
11797
}
11898

11999
String _getCurrentBlockAlign() {

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/_heading_and_text_items.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class _HeadingOrTextItem extends StatelessWidget {
8080
}
8181

8282
Future<void> _convert(bool isSelected) async {
83-
editorState.convertBlockType(
83+
await editorState.convertBlockType(
8484
blockType,
8585
isSelected: isSelected,
8686
extraAttributes: level != null
@@ -90,6 +90,14 @@ class _HeadingOrTextItem extends StatelessWidget {
9090
: null,
9191
selectionExtraInfo: {
9292
selectionExtraInfoDoNotAttachTextService: true,
93+
selectionExtraInfoDisableFloatingToolbar: true,
94+
},
95+
);
96+
await editorState.updateSelectionWithReason(
97+
editorState.selection,
98+
extraInfo: {
99+
selectionExtraInfoDisableFloatingToolbar: true,
100+
selectionExtraInfoDoNotAttachTextService: true,
93101
},
94102
);
95103
}

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/parsers/code_block_node_parser.dart

Lines changed: 0 additions & 23 deletions
This file was deleted.

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/parsers/divider_node_parser.dart

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
export 'callout_node_parser.dart';
2-
export 'code_block_node_parser.dart';
32
export 'custom_image_node_parser.dart';
4-
export 'divider_node_parser.dart';
53
export 'math_equation_node_parser.dart';
64
export 'toggle_list_node_parser.dart';
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
export 'callout_node_parser.dart';
2-
export 'code_block_node_parser.dart';
3-
export 'divider_node_parser.dart';
42
export 'math_equation_node_parser.dart';
53
export 'toggle_list_node_parser.dart';

frontend/appflowy_flutter/lib/workspace/application/export/document_exporter.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ import 'package:dartz/dartz.dart';
1111
import 'package:easy_localization/easy_localization.dart';
1212

1313
const List<NodeParser> _customParsers = [
14-
DividerNodeParser(),
1514
MathEquationNodeParser(),
16-
CodeBlockNodeParser(),
1715
CalloutNodeParser(),
1816
ToggleListNodeParser(),
1917
CustomImageNodeParser(),

frontend/appflowy_flutter/pubspec.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ packages:
5353
dependency: "direct main"
5454
description:
5555
path: "."
56-
ref: "49575bc"
57-
resolved-ref: "49575bc58f0332810e8aebbeae752eac77275d54"
56+
ref: "3d373be"
57+
resolved-ref: "3d373be64d28e13558e43d489728a6e0616821a9"
5858
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
5959
source: git
60-
version: "2.2.0"
60+
version: "2.3.0"
6161
appflowy_editor_plugins:
6262
dependency: "direct main"
6363
description:

frontend/appflowy_flutter/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ dependency_overrides:
164164
appflowy_editor:
165165
git:
166166
url: https://github.com/AppFlowy-IO/appflowy-editor.git
167-
ref: "49575bc"
167+
ref: "3d373be"
168168

169169
file: ^7.0.0
170170

0 commit comments

Comments
 (0)