Skip to content

Commit 71f880b

Browse files
committed
fix: some launch review issues
1 parent c7da516 commit 71f880b

File tree

6 files changed

+142
-42
lines changed

6 files changed

+142
-42
lines changed

frontend/appflowy_flutter/lib/mobile/presentation/inline_actions/mobile_inline_actions_menu_group.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ class MobileInlineActionsWidget extends StatelessWidget {
122122
item.icon!.call(isSelected),
123123
SizedBox(width: 12),
124124
],
125-
FlowyText.regular(
126-
item.label,
127-
figmaLineHeight: 18,
128-
overflow: TextOverflow.ellipsis,
129-
fontSize: 16,
130-
color: style.menuItemSelectedTextColor,
125+
Flexible(
126+
child: FlowyText.regular(
127+
item.label,
128+
figmaLineHeight: 18,
129+
overflow: TextOverflow.ellipsis,
130+
fontSize: 16,
131+
color: style.menuItemSelectedTextColor,
132+
),
131133
),
132134
],
133135
),

frontend/appflowy_flutter/lib/mobile/presentation/selection_menu/mobile_selection_menu_widget.dart

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
55

66
import 'mobile_selection_menu_item.dart';
77
import 'mobile_selection_menu_item_widget.dart';
8+
import 'slash_keyboard_service_interceptor.dart';
89

910
class MobileSelectionMenuWidget extends StatefulWidget {
1011
const MobileSelectionMenuWidget({
@@ -61,6 +62,8 @@ class _MobileSelectionMenuWidgetState extends State<MobileSelectionMenuWidget> {
6162

6263
int selectedIndex = 0;
6364

65+
late AppFlowyKeyboardServiceInterceptor keyboardInterceptor;
66+
6467
List<SelectionMenuItem> get filterItems {
6568
final List<SelectionMenuItem> items = [];
6669
for (final item in widget.items) {
@@ -117,33 +120,51 @@ class _MobileSelectionMenuWidgetState extends State<MobileSelectionMenuWidget> {
117120
@override
118121
void initState() {
119122
super.initState();
120-
121-
final List<SelectionMenuItem> items = [];
122-
for (final item in widget.items) {
123-
if (item is MobileSelectionMenuItem) {
124-
item.onSelected = () {
125-
if (mounted) {
126-
setState(() {
127-
_showingItems = item.children
128-
.map((e) => e..onSelected = widget.onExit)
129-
.toList();
130-
});
131-
}
132-
};
133-
}
134-
items.add(item);
135-
}
136-
_showingItems = items;
123+
_showingItems = buildInitialItems();
137124

138125
keepEditorFocusNotifier.increase();
139126
WidgetsBinding.instance.addPostFrameCallback((_) {
140127
_focusNode.requestFocus();
141128
});
129+
130+
keyboardInterceptor = SlashKeyboardServiceInterceptor(
131+
onDelete: () async {
132+
if (!mounted) return false;
133+
final hasItemsChanged = !isInitialItems();
134+
if (keyword.isEmpty && hasItemsChanged) {
135+
setState(() {
136+
_showingItems = buildInitialItems();
137+
selectedIndex = 0;
138+
});
139+
return true;
140+
}
141+
return false;
142+
},
143+
onEnter: () {
144+
if (!mounted) return;
145+
if (_showingItems.isEmpty) return;
146+
final item = _showingItems[selectedIndex];
147+
if (item is MobileSelectionMenuItem) {
148+
selectedIndex = 0;
149+
item.onSelected?.call();
150+
} else {
151+
item.handler(
152+
editorState,
153+
menuService,
154+
context,
155+
);
156+
}
157+
},
158+
);
159+
editorState.service.keyboardService
160+
?.registerInterceptor(keyboardInterceptor);
142161
editorState.selectionNotifier.addListener(onSelectionChanged);
143162
}
144163

145164
@override
146165
void dispose() {
166+
editorState.service.keyboardService
167+
?.unregisterInterceptor(keyboardInterceptor);
147168
editorState.selectionNotifier.removeListener(onSelectionChanged);
148169
_focusNode.dispose();
149170
keepEditorFocusNotifier.decrease();
@@ -295,4 +316,34 @@ class _MobileSelectionMenuWidgetState extends State<MobileSelectionMenuWidget> {
295316
),
296317
);
297318
}
319+
320+
List<SelectionMenuItem> buildInitialItems() {
321+
final List<SelectionMenuItem> items = [];
322+
for (final item in widget.items) {
323+
if (item is MobileSelectionMenuItem) {
324+
item.onSelected = () {
325+
if (mounted) {
326+
setState(() {
327+
_showingItems = item.children
328+
.map((e) => e..onSelected = widget.onExit)
329+
.toList();
330+
});
331+
}
332+
};
333+
}
334+
items.add(item);
335+
}
336+
return items;
337+
}
338+
339+
bool isInitialItems() {
340+
if (_showingItems.length != widget.items.length) return false;
341+
int i = 0;
342+
for (final item in _showingItems) {
343+
final widgetItem = widget.items[i];
344+
if (widgetItem.name != item.name) return false;
345+
i++;
346+
}
347+
return true;
348+
}
298349
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import 'package:appflowy/plugins/document/presentation/editor_plugins/keyboard_interceptor/keyboard_interceptor.dart';
2+
import 'package:appflowy_editor/appflowy_editor.dart';
3+
import 'package:flutter/foundation.dart';
4+
import 'package:flutter/services.dart';
5+
6+
class SlashKeyboardServiceInterceptor extends EditorKeyboardInterceptor {
7+
SlashKeyboardServiceInterceptor({
8+
required this.onDelete,
9+
required this.onEnter,
10+
});
11+
12+
final AsyncValueGetter<bool> onDelete;
13+
final VoidCallback onEnter;
14+
15+
@override
16+
Future<bool> interceptDelete(
17+
TextEditingDeltaDeletion deletion,
18+
EditorState editorState,
19+
) async {
20+
final intercept = await onDelete.call();
21+
if (intercept) {
22+
return true;
23+
} else {
24+
return super.interceptDelete(deletion, editorState);
25+
}
26+
}
27+
28+
@override
29+
Future<bool> interceptInsert(
30+
TextEditingDeltaInsertion insertion,
31+
EditorState editorState,
32+
List<CharacterShortcutEvent> characterShortcutEvents,
33+
) async {
34+
final text = insertion.textInserted;
35+
if (text.contains('\n')) {
36+
onEnter.call();
37+
return true;
38+
}
39+
return super
40+
.interceptInsert(insertion, editorState, characterShortcutEvents);
41+
}
42+
}

frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/mobile_items.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@ final List<SelectionMenuItem> mobileItems = [
1111
textStyleMobileSlashMenuItem,
1212
listMobileSlashMenuItem,
1313
toggleListMobileSlashMenuItem,
14-
fileOrMediaMobileSlashMenuItem,
15-
decorationsMobileSlashMenuItem,
14+
fileAndMediaMobileSlashMenuItem,
1615
tableSlashMenuItem,
16+
visualsMobileSlashMenuItem,
1717
dateOrReminderSlashMenuItem,
18+
subPageSlashMenuItem,
1819
advancedMobileSlashMenuItem,
1920
];
2021

2122
final List<SelectionMenuItem> mobileItemsInTale = [
2223
textStyleMobileSlashMenuItem,
2324
listMobileSlashMenuItem,
2425
toggleListMobileSlashMenuItem,
25-
fileOrMediaMobileSlashMenuItem,
26-
decorationsMobileSlashMenuItem,
26+
fileAndMediaMobileSlashMenuItem,
27+
visualsMobileSlashMenuItem,
2728
dateOrReminderSlashMenuItem,
29+
subPageSlashMenuItem,
2830
advancedMobileSlashMenuItem,
2931
];
3032

@@ -64,7 +66,7 @@ MobileSelectionMenuItem listMobileSlashMenuItem = MobileSelectionMenuItem(
6466
);
6567

6668
MobileSelectionMenuItem toggleListMobileSlashMenuItem = MobileSelectionMenuItem(
67-
getName: LocaleKeys.document_slashMenu_name_toggleList.tr,
69+
getName: LocaleKeys.document_slashMenu_name_toggle.tr,
6870
handler: _handler,
6971
icon: (_, isSelected, style) => SelectableSvgWidget(
7072
data: FlowySvgs.slash_menu_icon_toggle_s,
@@ -80,9 +82,9 @@ MobileSelectionMenuItem toggleListMobileSlashMenuItem = MobileSelectionMenuItem(
8082
],
8183
);
8284

83-
MobileSelectionMenuItem fileOrMediaMobileSlashMenuItem =
85+
MobileSelectionMenuItem fileAndMediaMobileSlashMenuItem =
8486
MobileSelectionMenuItem(
85-
getName: LocaleKeys.document_slashMenu_name_fileOrMedia.tr,
87+
getName: LocaleKeys.document_slashMenu_name_fileAndMedia.tr,
8688
handler: _handler,
8789
icon: (_, isSelected, style) => SelectableSvgWidget(
8890
data: FlowySvgs.slash_menu_icon_file_s,
@@ -97,9 +99,8 @@ MobileSelectionMenuItem fileOrMediaMobileSlashMenuItem =
9799
],
98100
);
99101

100-
MobileSelectionMenuItem decorationsMobileSlashMenuItem =
101-
MobileSelectionMenuItem(
102-
getName: LocaleKeys.document_slashMenu_name_decorations.tr,
102+
MobileSelectionMenuItem visualsMobileSlashMenuItem = MobileSelectionMenuItem(
103+
getName: LocaleKeys.document_slashMenu_name_visuals.tr,
103104
handler: _handler,
104105
icon: (_, isSelected, style) => SelectableSvgWidget(
105106
data: FlowySvgs.slash_menu_icon_simple_table_s,
@@ -108,8 +109,9 @@ MobileSelectionMenuItem decorationsMobileSlashMenuItem =
108109
),
109110
nameBuilder: slashMenuItemNameBuilder,
110111
children: [
111-
quoteSlashMenuItem,
112+
calloutSlashMenuItem,
112113
dividerSlashMenuItem,
114+
quoteSlashMenuItem,
113115
],
114116
);
115117

@@ -123,8 +125,6 @@ MobileSelectionMenuItem advancedMobileSlashMenuItem = MobileSelectionMenuItem(
123125
),
124126
nameBuilder: slashMenuItemNameBuilder,
125127
children: [
126-
subPageSlashMenuItem,
127-
calloutSlashMenuItem,
128128
codeBlockSlashMenuItem,
129129
mathEquationSlashMenuItem,
130130
],

frontend/appflowy_flutter/lib/plugins/inline_actions/widgets/inline_actions_menu_group.dart

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,12 @@ class _InlineActionsWidgetState extends State<InlineActionsWidget> {
107107
icon.call(widget.isSelected),
108108
SizedBox(width: 12),
109109
],
110-
FlowyText.regular(
111-
widget.item.label,
112-
figmaLineHeight: 18,
113-
overflow: TextOverflow.ellipsis,
110+
Flexible(
111+
child: FlowyText.regular(
112+
widget.item.label,
113+
figmaLineHeight: 18,
114+
overflow: TextOverflow.ellipsis,
115+
),
114116
),
115117
],
116118
),

frontend/resources/translations/en.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,8 +1689,11 @@
16891689
"name": {
16901690
"textStyle": "Text Style",
16911691
"list": "List",
1692-
"fileOrMedia": "File or Media",
1693-
"decorations": "Decorations",
1692+
"toggle": "Toggle",
1693+
"fileAndMedia": "File & Media",
1694+
"simpleTable": "Simple Table",
1695+
"visuals": "Visuals",
1696+
"document": "Document",
16941697
"advanced": "Advanced",
16951698
"text": "Text",
16961699
"heading1": "Heading 1",

0 commit comments

Comments
 (0)