mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: [Bug] Text formatting toolbar disappear under layout #1542
This commit is contained in:
parent
c64b83c2d6
commit
49574d3ff0
@ -16,12 +16,14 @@ class ToolbarWidget extends StatefulWidget {
|
|||||||
required this.layerLink,
|
required this.layerLink,
|
||||||
required this.offset,
|
required this.offset,
|
||||||
required this.items,
|
required this.items,
|
||||||
|
this.aligment = Alignment.topLeft,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final EditorState editorState;
|
final EditorState editorState;
|
||||||
final LayerLink layerLink;
|
final LayerLink layerLink;
|
||||||
final Offset offset;
|
final Offset offset;
|
||||||
final List<ToolbarItem> items;
|
final List<ToolbarItem> items;
|
||||||
|
final Alignment aligment;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ToolbarWidget> createState() => _ToolbarWidgetState();
|
State<ToolbarWidget> createState() => _ToolbarWidgetState();
|
||||||
@ -39,6 +41,7 @@ class _ToolbarWidgetState extends State<ToolbarWidget> with ToolbarMixin {
|
|||||||
link: widget.layerLink,
|
link: widget.layerLink,
|
||||||
showWhenUnlinked: true,
|
showWhenUnlinked: true,
|
||||||
offset: widget.offset,
|
offset: widget.offset,
|
||||||
|
followerAnchor: widget.aligment,
|
||||||
child: _buildToolbar(context),
|
child: _buildToolbar(context),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -388,9 +388,11 @@ class _AppFlowySelectionState extends State<AppFlowySelection>
|
|||||||
|
|
||||||
// TODO: need to be refactored.
|
// TODO: need to be refactored.
|
||||||
Offset? toolbarOffset;
|
Offset? toolbarOffset;
|
||||||
|
Alignment? alignment;
|
||||||
LayerLink? layerLink;
|
LayerLink? layerLink;
|
||||||
final editorOffset =
|
final editorOffset =
|
||||||
editorState.renderBox?.localToGlobal(Offset.zero) ?? Offset.zero;
|
editorState.renderBox?.localToGlobal(Offset.zero) ?? Offset.zero;
|
||||||
|
final editorSize = editorState.renderBox?.size ?? Size.zero;
|
||||||
|
|
||||||
final backwardNodes =
|
final backwardNodes =
|
||||||
selection.isBackward ? nodes : nodes.reversed.toList(growable: false);
|
selection.isBackward ? nodes : nodes.reversed.toList(growable: false);
|
||||||
@ -438,10 +440,33 @@ class _AppFlowySelectionState extends State<AppFlowySelection>
|
|||||||
// TODO: Need to compute more precise location.
|
// TODO: Need to compute more precise location.
|
||||||
if ((selectionRect.topLeft.dy - editorOffset.dy) <=
|
if ((selectionRect.topLeft.dy - editorOffset.dy) <=
|
||||||
baseToolbarOffset.dy) {
|
baseToolbarOffset.dy) {
|
||||||
toolbarOffset ??= rect.bottomLeft;
|
if (selectionRect.topLeft.dx <=
|
||||||
|
editorSize.width / 3.0 + editorOffset.dx) {
|
||||||
|
toolbarOffset ??= rect.bottomLeft;
|
||||||
|
alignment ??= Alignment.topLeft;
|
||||||
|
} else if (selectionRect.topRight.dx >=
|
||||||
|
editorSize.width * 2.0 / 3.0 + editorOffset.dx) {
|
||||||
|
toolbarOffset ??= rect.bottomRight;
|
||||||
|
alignment ??= Alignment.topRight;
|
||||||
|
} else {
|
||||||
|
toolbarOffset ??= rect.bottomCenter;
|
||||||
|
alignment ??= Alignment.topCenter;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
toolbarOffset ??= rect.topLeft - baseToolbarOffset;
|
if (selectionRect.topLeft.dx <=
|
||||||
|
editorSize.width / 3.0 + editorOffset.dx) {
|
||||||
|
toolbarOffset ??= rect.topLeft - baseToolbarOffset;
|
||||||
|
alignment ??= Alignment.topLeft;
|
||||||
|
} else if (selectionRect.topRight.dx >=
|
||||||
|
editorSize.width * 2.0 / 3.0 + editorOffset.dx) {
|
||||||
|
toolbarOffset ??= rect.topRight - baseToolbarOffset;
|
||||||
|
alignment ??= Alignment.topRight;
|
||||||
|
} else {
|
||||||
|
toolbarOffset ??= rect.topCenter - baseToolbarOffset;
|
||||||
|
alignment ??= Alignment.topCenter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
layerLink ??= node.layerLink;
|
layerLink ??= node.layerLink;
|
||||||
|
|
||||||
final overlay = OverlayEntry(
|
final overlay = OverlayEntry(
|
||||||
@ -460,6 +485,7 @@ class _AppFlowySelectionState extends State<AppFlowySelection>
|
|||||||
if (toolbarOffset != null && layerLink != null) {
|
if (toolbarOffset != null && layerLink != null) {
|
||||||
editorState.service.toolbarService?.showInOffset(
|
editorState.service.toolbarService?.showInOffset(
|
||||||
toolbarOffset,
|
toolbarOffset,
|
||||||
|
alignment!,
|
||||||
layerLink,
|
layerLink,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import 'package:appflowy_editor/src/extensions/object_extensions.dart';
|
|||||||
|
|
||||||
abstract class AppFlowyToolbarService {
|
abstract class AppFlowyToolbarService {
|
||||||
/// Show the toolbar widget beside the offset.
|
/// Show the toolbar widget beside the offset.
|
||||||
void showInOffset(Offset offset, LayerLink layerLink);
|
void showInOffset(Offset offset, Alignment alignment, LayerLink layerLink);
|
||||||
|
|
||||||
/// Hide the toolbar widget.
|
/// Hide the toolbar widget.
|
||||||
void hide();
|
void hide();
|
||||||
@ -37,7 +37,7 @@ class _FlowyToolbarState extends State<FlowyToolbar>
|
|||||||
final _toolbarWidgetKey = GlobalKey(debugLabel: '_toolbar_widget');
|
final _toolbarWidgetKey = GlobalKey(debugLabel: '_toolbar_widget');
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void showInOffset(Offset offset, LayerLink layerLink) {
|
void showInOffset(Offset offset, Alignment alignment, LayerLink layerLink) {
|
||||||
hide();
|
hide();
|
||||||
final items = _filterItems(defaultToolbarItems);
|
final items = _filterItems(defaultToolbarItems);
|
||||||
if (items.isEmpty) {
|
if (items.isEmpty) {
|
||||||
@ -50,6 +50,7 @@ class _FlowyToolbarState extends State<FlowyToolbar>
|
|||||||
layerLink: layerLink,
|
layerLink: layerLink,
|
||||||
offset: offset,
|
offset: offset,
|
||||||
items: items,
|
items: items,
|
||||||
|
aligment: alignment,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
Overlay.of(context)?.insert(_toolbarOverlay!);
|
Overlay.of(context)?.insert(_toolbarOverlay!);
|
||||||
|
Loading…
Reference in New Issue
Block a user