diff --git a/lib/src/editor/toolbar/desktop/floating_toolbar.dart b/lib/src/editor/toolbar/desktop/floating_toolbar.dart index fcaea8162..90ec0a338 100644 --- a/lib/src/editor/toolbar/desktop/floating_toolbar.dart +++ b/lib/src/editor/toolbar/desktop/floating_toolbar.dart @@ -210,15 +210,18 @@ class _FloatingToolbarState extends State final right = (rect.right - editorCenter.dx).abs(); final width = editorSize.width; final threshold = width / 3.0; + final top = rect.top < floatingToolbarHeight + ? rect.bottom + floatingToolbarHeight + : rect.top; if (rect.left >= threshold && rect.right <= threshold * 2.0) { // show in center - return (rect.top, threshold, null); + return (top, threshold, null); } else if (left >= right) { // show in left - return (rect.top, rect.left, null); + return (top, rect.left, null); } else { // show in right - return (rect.top, null, editorRect.right - rect.right); + return (top, null, editorRect.right - rect.right); } } } diff --git a/test/new/infra/testable_editor.dart b/test/new/infra/testable_editor.dart index 4596e9d55..703db5c80 100644 --- a/test/new/infra/testable_editor.dart +++ b/test/new/infra/testable_editor.dart @@ -34,16 +34,40 @@ class TestableEditor { bool autoFocus = false, bool editable = true, bool shrinkWrap = false, + bool withFloatingToolbar = false, ScrollController? scrollController, Widget Function(Widget child)? wrapper, }) async { - final editor = AppFlowyEditor.standard( + await AppFlowyEditorLocalizations.load(locale); + + if (withFloatingToolbar) { + scrollController ??= ScrollController(); + } + Widget editor = AppFlowyEditor.standard( editorState: editorState, editable: editable, autoFocus: autoFocus, shrinkWrap: shrinkWrap, scrollController: scrollController, ); + if (withFloatingToolbar) { + editor = FloatingToolbar( + items: [ + paragraphItem, + ...headingItems, + ...markdownFormatItems, + quoteItem, + bulletedListItem, + numberedListItem, + linkItem, + textColorItem, + highlightColorItem + ], + editorState: editorState, + scrollController: scrollController!, + child: editor, + ); + } await tester.pumpWidget( MaterialApp( localizationsDelegates: const [ diff --git a/test/new/toolbar/desktop/floating_toolbar_test.dart b/test/new/toolbar/desktop/floating_toolbar_test.dart new file mode 100644 index 000000000..a4305f8ff --- /dev/null +++ b/test/new/toolbar/desktop/floating_toolbar_test.dart @@ -0,0 +1,36 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../../util/util.dart'; +import '../../infra/testable_editor.dart'; + +void main() async { + group('floating toolbar', () { + const text = 'Welcome to AppFlowy Editor 🔥!'; + + testWidgets( + 'select the first line of the document, the toolbar should not be blocked', + (tester) async { + final editor = tester.editor..addParagraphs(3, initialText: text); + await editor.startTesting( + withFloatingToolbar: true, + ); + + final selection = Selection.single( + path: [0], + startOffset: 0, + endOffset: text.length, + ); + await editor.updateSelection(selection); + await tester.pumpAndSettle(); + + final floatingToolbar = find.byType(FloatingToolbarWidget); + expect(floatingToolbar, findsOneWidget); + expect(tester.getTopLeft(floatingToolbar).dy >= 0, true); + await editor.dispose(); + }); + }); +}