Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt position with viewport offset when hit testing children #399

Merged
merged 2 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/fleather/lib/src/rendering/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,8 @@ class RenderEditor extends RenderEditableContainerBox

@override
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) {
return defaultHitTestChildren(result, position: position);
final Offset effectivePosition = position - paintOffset;
return defaultHitTestChildren(result, position: effectivePosition);
}

void _paintHandleLayers(
Expand Down
52 changes: 52 additions & 0 deletions packages/fleather/test/widgets/editor_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:fleather/fleather.dart';
import 'package:fleather/src/services/spell_check_suggestions_toolbar.dart';
import 'package:fleather/src/widgets/checkbox.dart';
import 'package:fleather/src/widgets/keyboard_listener.dart';
import 'package:fleather/src/widgets/text_selection.dart';
import 'package:flutter/cupertino.dart';
Expand Down Expand Up @@ -101,6 +102,57 @@ void main() {
tester.view.viewInsets = FakeViewPadding.zero;
});

testWidgets('Allows children to capture events when scrolled',
(tester) async {
Delta generateDelta({required bool withBoxChecked}) {
var delta = Delta();
List.generate(20, (_) => delta.insert('Test\n'));
return delta
..insert('\n')
..insert('some check box')
..insert('\n', {'block': 'cl', 'checked': withBoxChecked});
}

final delta = generateDelta(withBoxChecked: false);
final controller =
FleatherController(document: ParchmentDocument.fromDelta(delta));
final embedHeight =
(tester.view.physicalSize / tester.view.devicePixelRatio).height *
1.5;
final scrollController = ScrollController();
final editor = MaterialApp(
home: Scaffold(
body: Column(
children: [
Expanded(
child: FleatherEditor(
controller: controller,
scrollController: scrollController,
embedBuilder: (context, node) => SizedBox(
width: 100,
height: embedHeight,
),
),
),
],
),
),
);
await tester.pumpWidget(editor);
final renderEditor =
tester.state<EditorState>(find.byType(RawEditor)).renderEditor;
scrollController.jumpTo(scrollController.position.maxScrollExtent);
await tester.pumpAndSettle();
final checkBox = find.byType(FleatherCheckbox);
expect(checkBox, findsOneWidget);
await tester.tapAt(tester.getCenter(checkBox) + renderEditor.paintOffset);
await tester.pumpAndSettle();
tester.binding.scheduleWarmUpFrame();
await tester.pumpAndSettle();
expect(
controller.document.toDelta(), generateDelta(withBoxChecked: true));
});

testWidgets('Keep selectiontoolbar with editor bounds', (tester) async {
final delta = Delta();
for (int i = 0; i < 30; i++) {
Expand Down
Loading