fix: block option interceptor (#6739)

* fix: use unique key in interceptor

* test: add block option interaction tests
This commit is contained in:
Mathias Mogensen 2024-11-07 02:47:47 +01:00 committed by GitHub
parent 6785104c3a
commit 97999aee44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 53 additions and 5 deletions

View File

@ -0,0 +1,47 @@
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() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('Block option interaction tests', () {
testWidgets('has correct block selection on tap option button',
(tester) async {
await tester.initializeAppFlowy();
await tester.tapAnonymousSignInButton();
// We edit the document by entering some characters, to ensure the document has focus
await tester.editor.updateSelection(
Selection.collapsed(Position(path: [2])),
);
// Insert character 'a' three times - easy to identify
await tester.ime.insertText('aaa');
await tester.pumpAndSettle();
final editorState = tester.editor.getCurrentEditorState();
final node = editorState.getNodeAtPath([2]);
expect(node?.delta?.toPlainText(), startsWith('aaa'));
final multiSelection = Selection(
start: Position(path: [2], offset: 3),
end: Position(path: [4], offset: 40),
);
// Select multiple items
await tester.editor.updateSelection(multiSelection);
await tester.pumpAndSettle();
// Press the block option menu
await tester.editor.hoverAndClickOptionMenuButton([2]);
await tester.pumpAndSettle();
// Expect the selection to be Block type and not have changed
expect(editorState.selectionType, SelectionType.block);
expect(editorState.selection, multiSelection);
});
});
}

View File

@ -8,6 +8,7 @@ import 'document_with_file_test.dart' as document_with_file_test;
import 'document_with_image_block_test.dart' as document_with_image_block_test;
import 'document_with_multi_image_block_test.dart'
as document_with_multi_image_block_test;
import 'document_block_option_test.dart' as document_block_option_test;
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
@ -19,7 +20,5 @@ void main() {
document_more_actions_test.main();
document_with_file_test.main();
document_shortcuts_test.main();
// Disable subPage test temporarily, enable it in version 0.7.2
// document_sub_page_test.main();
document_block_option_test.main();
}

View File

@ -30,8 +30,10 @@ class OptionButton extends StatefulWidget {
}
class _OptionButtonState extends State<OptionButton> {
late final registerKey =
_interceptorKey + widget.blockComponentContext.node.id;
late final gestureInterceptor = SelectionGestureInterceptor(
key: _interceptorKey,
key: registerKey,
canTap: (details) => !_isTapInBounds(details.globalPosition),
);
@ -52,7 +54,7 @@ class _OptionButtonState extends State<OptionButton> {
@override
void dispose() {
widget.editorState.service.selectionService.unregisterGestureInterceptor(
_interceptorKey,
registerKey,
);
super.dispose();