mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-12-12 23:51:55 +00:00
feat: resume selection on window focus (#6455)
This commit is contained in:
parent
0d69b895aa
commit
b36babf754
@ -0,0 +1,32 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
|
||||
import '../../shared/util.dart';
|
||||
|
||||
void main() {
|
||||
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('Editor AppLifeCycle tests', () {
|
||||
testWidgets(
|
||||
'Selection is added back after pausing AppFlowy',
|
||||
(tester) async {
|
||||
await tester.initializeAppFlowy();
|
||||
await tester.tapAnonymousSignInButton();
|
||||
|
||||
final selection = Selection.single(path: [4], startOffset: 0);
|
||||
await tester.editor.updateSelection(selection);
|
||||
|
||||
binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
|
||||
expect(tester.editor.getCurrentEditorState().selection, null);
|
||||
|
||||
binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.editor.getCurrentEditorState().selection, selection);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -4,6 +4,8 @@ import 'desktop/board/board_test_runner.dart' as board_test_runner;
|
||||
import 'desktop/database/database_row_cover_test.dart'
|
||||
as database_row_cover_test;
|
||||
import 'desktop/document/document_title_test.dart' as document_title_test;
|
||||
import 'desktop/document/document_app_lifecycle_test.dart'
|
||||
as document_app_lifecycle_test;
|
||||
import 'desktop/document/document_sub_page_test.dart' as document_sub_page_test;
|
||||
import 'desktop/grid/grid_filter_and_sort_test.dart'
|
||||
as grid_filter_and_sort_test_runner;
|
||||
@ -11,8 +13,8 @@ import 'desktop/grid/grid_reopen_test.dart' as grid_reopen_test_runner;
|
||||
import 'desktop/grid/grid_reorder_row_test.dart'
|
||||
as grid_reorder_row_test_runner;
|
||||
import 'desktop/grid/grid_edit_row_test.dart' as grid_edit_row_test_runner;
|
||||
import 'desktop/settings/settings_runner.dart' as settings_test_runner;
|
||||
import 'desktop/grid/grid_row_test.dart' as grid_create_row_test_runner;
|
||||
import 'desktop/settings/settings_runner.dart' as settings_test_runner;
|
||||
import 'desktop/sidebar/sidebar_test_runner.dart' as sidebar_test_runner;
|
||||
import 'desktop/uncategorized/emoji_shortcut_test.dart' as emoji_shortcut_test;
|
||||
import 'desktop/uncategorized/empty_test.dart' as first_test;
|
||||
@ -51,4 +53,5 @@ Future<void> runIntegration3OnDesktop() async {
|
||||
zoom_in_out_test.main();
|
||||
document_title_test.main();
|
||||
document_sub_page_test.main();
|
||||
document_app_lifecycle_test.main();
|
||||
}
|
||||
|
||||
@ -58,7 +58,8 @@ class AppFlowyEditorPage extends StatefulWidget {
|
||||
State<AppFlowyEditorPage> createState() => _AppFlowyEditorPageState();
|
||||
}
|
||||
|
||||
class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
|
||||
class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
|
||||
with WidgetsBindingObserver {
|
||||
late final ScrollController effectiveScrollController;
|
||||
|
||||
late final InlineActionsService inlineActionsService = InlineActionsService(
|
||||
@ -126,6 +127,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
|
||||
if (widget.useViewInfoBloc) {
|
||||
viewInfoBloc.add(
|
||||
@ -163,6 +165,8 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
|
||||
// customize the dynamic theme color
|
||||
_customizeBlockComponentBackgroundColorDecorator();
|
||||
|
||||
widget.editorState.selectionNotifier.addListener(onSelectionChanged);
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) {
|
||||
return;
|
||||
@ -181,6 +185,24 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
|
||||
});
|
||||
}
|
||||
|
||||
Selection? previousSelection;
|
||||
|
||||
void onSelectionChanged() {
|
||||
if (widget.editorState.isDisposed || widget.editorState.selection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
previousSelection = widget.editorState.selection;
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
super.didChangeAppLifecycleState(state);
|
||||
if (state == AppLifecycleState.resumed && !widget.editorState.isDisposed) {
|
||||
widget.editorState.selection = previousSelection;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
final currFocusManager = AFFocusManager.maybeOf(context);
|
||||
@ -202,6 +224,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.editorState.selectionNotifier.removeListener(onSelectionChanged);
|
||||
widget.editorState.service.keyboardService?.unregisterInterceptor(
|
||||
editorKeyboardInterceptor,
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user