Skip to content

Commit

Permalink
fix: block selection overflow (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 authored Jul 13, 2023
1 parent 2ab67ee commit 33b18d9
Show file tree
Hide file tree
Showing 23 changed files with 313 additions and 617 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,21 @@ import 'package:flutter/material.dart';
class NestedListWidget extends StatelessWidget {
const NestedListWidget({
super.key,
this.indentPadding = const EdgeInsets.only(left: 30),
required this.child,
required this.children,
});

/// used to indent the nested list when the children's level is greater than 1.
///
/// For example,
///
/// Hello AppFlowy
/// Hello AppFlowy
/// ↑
/// the indent padding is applied to the second line.
final EdgeInsets indentPadding;

final Widget child;
final List<Widget> children;

Expand All @@ -18,11 +29,14 @@ class NestedListWidget extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
child,
Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
Padding(
padding: indentPadding,
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: children,
),
),
],
);
Expand Down
1 change: 0 additions & 1 deletion lib/src/editor/block_component/block_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export 'base_component/convert_to_paragraph_command.dart';
export 'base_component/insert_newline_in_type_command.dart';
export 'base_component/indent_command.dart';
export 'base_component/outdent_command.dart';
export 'base_component/block_component_padding.dart';
export 'base_component/widget/full_screen_overlay_entry.dart';
export 'base_component/widget/ignore_parent_pointer.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,24 @@ class _BulletedListBlockComponentWidgetState
@override
GlobalKey<State<StatefulWidget>> get containerKey => widget.node.key;

@override
GlobalKey<State<StatefulWidget>> blockComponentKey = GlobalKey(
debugLabel: BulletedListBlockKeys.type,
);

@override
BlockComponentConfiguration get configuration => widget.configuration;

@override
Node get node => widget.node;

String? lastStartText;
TextDirection? lastDirection;
@override
EdgeInsets get indentPadding => configuration.indentPadding(
node,
calculateTextDirection(
defaultTextDirection: Directionality.maybeOf(context),
),
);

@override
Widget buildComponent(BuildContext context) {
Expand Down Expand Up @@ -147,6 +157,12 @@ class _BulletedListBlockComponentWidgetState
),
);

child = Padding(
key: blockComponentKey,
padding: padding,
child: child,
);

if (widget.showActions && widget.actionBuilder != null) {
child = BlockComponentActionWrapper(
node: node,
Expand All @@ -155,13 +171,7 @@ class _BulletedListBlockComponentWidgetState
);
}

final indentPadding = configuration.indentPadding(node, textDirection);
return BlockComponentPadding(
node: node,
padding: padding,
indentPadding: indentPadding,
child: child,
);
return child;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class _DividerBlockComponentWidgetState
@override
Widget build(BuildContext context) {
Widget child = Container(
key: dividerKey,
height: widget.height,
alignment: Alignment.center,
child: Divider(
Expand All @@ -91,19 +90,21 @@ class _DividerBlockComponentWidgetState
),
);

child = Padding(
key: dividerKey,
padding: padding,
child: child,
);

if (widget.showActions && widget.actionBuilder != null) {
child = BlockComponentActionWrapper(
node: widget.node,
node: node,
actionBuilder: widget.actionBuilder!,
child: child,
);
}

return BlockComponentPadding(
node: node,
padding: padding,
child: child,
);
return child;
}

@override
Expand All @@ -121,6 +122,11 @@ class _DividerBlockComponentWidgetState
@override
CursorStyle get cursorStyle => CursorStyle.cover;

@override
Rect getBlockRect() {
return getCursorRectInPosition(Position.invalid()) ?? Rect.zero;
}

@override
Rect? getCursorRectInPosition(Position position) {
final size = _renderBox.size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ class _HeadingBlockComponentWidgetState
@override
GlobalKey<State<StatefulWidget>> get containerKey => widget.node.key;

@override
GlobalKey<State<StatefulWidget>> blockComponentKey = GlobalKey(
debugLabel: HeadingBlockKeys.type,
);

@override
BlockComponentConfiguration get configuration => widget.configuration;

Expand Down Expand Up @@ -145,6 +150,12 @@ class _HeadingBlockComponentWidgetState
),
);

child = Padding(
key: blockComponentKey,
padding: padding,
child: child,
);

if (widget.showActions && widget.actionBuilder != null) {
child = BlockComponentActionWrapper(
node: node,
Expand All @@ -153,13 +164,7 @@ class _HeadingBlockComponentWidgetState
);
}

final indentPadding = configuration.indentPadding(node, textDirection);
return BlockComponentPadding(
node: node,
padding: padding,
indentPadding: indentPadding,
child: child,
);
return child;
}

TextStyle? defaultTextStyle(int level) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ class ImageBlockComponentWidgetState extends State<ImageBlockComponentWidget>
final height = attributes[ImageBlockKeys.height]?.toDouble();

Widget child = ResizableImage(
key: imageKey,
src: src,
width: width,
height: height,
Expand All @@ -158,6 +157,12 @@ class ImageBlockComponentWidgetState extends State<ImageBlockComponentWidget>
},
);

child = Padding(
key: imageKey,
padding: padding,
child: child,
);

if (widget.showActions && widget.actionBuilder != null) {
child = BlockComponentActionWrapper(
node: node,
Expand Down Expand Up @@ -191,11 +196,7 @@ class ImageBlockComponentWidgetState extends State<ImageBlockComponentWidget>
);
}

return BlockComponentPadding(
node: node,
padding: padding,
child: child,
);
return child;
}

@override
Expand All @@ -213,6 +214,11 @@ class ImageBlockComponentWidgetState extends State<ImageBlockComponentWidget>
@override
CursorStyle get cursorStyle => CursorStyle.cover;

@override
Rect getBlockRect() {
return getCursorRectInPosition(Position.invalid()) ?? Rect.zero;
}

@override
Rect? getCursorRectInPosition(Position position) {
final size = _renderBox.size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,25 @@ class _NumberedListBlockComponentWidgetState
@override
GlobalKey<State<StatefulWidget>> get containerKey => widget.node.key;

@override
GlobalKey<State<StatefulWidget>> blockComponentKey = GlobalKey(
debugLabel: NumberedListBlockKeys.type,
);

@override
BlockComponentConfiguration get configuration => widget.configuration;

@override
Node get node => widget.node;

@override
EdgeInsets get indentPadding => configuration.indentPadding(
node,
calculateTextDirection(
defaultTextDirection: Directionality.maybeOf(context),
),
);

@override
Widget buildComponent(BuildContext context) {
final textDirection = calculateTextDirection(
Expand Down Expand Up @@ -150,6 +163,12 @@ class _NumberedListBlockComponentWidgetState
),
);

child = Padding(
key: blockComponentKey,
padding: padding,
child: child,
);

if (widget.showActions && widget.actionBuilder != null) {
child = BlockComponentActionWrapper(
node: node,
Expand All @@ -158,13 +177,7 @@ class _NumberedListBlockComponentWidgetState
);
}

final indentPadding = configuration.indentPadding(node, textDirection);
return BlockComponentPadding(
node: node,
padding: padding,
indentPadding: indentPadding,
child: child,
);
return child;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ class _QuoteBlockComponentWidgetState extends State<QuoteBlockComponentWidget>
@override
GlobalKey<State<StatefulWidget>> get containerKey => widget.node.key;

@override
GlobalKey<State<StatefulWidget>> blockComponentKey = GlobalKey(
debugLabel: QuoteBlockKeys.type,
);

@override
BlockComponentConfiguration get configuration => widget.configuration;

Expand Down Expand Up @@ -141,6 +146,12 @@ class _QuoteBlockComponentWidgetState extends State<QuoteBlockComponentWidget>
),
);

child = Padding(
key: blockComponentKey,
padding: padding,
child: child,
);

if (widget.showActions && widget.actionBuilder != null) {
child = BlockComponentActionWrapper(
node: node,
Expand All @@ -149,13 +160,7 @@ class _QuoteBlockComponentWidgetState extends State<QuoteBlockComponentWidget>
);
}

final indentPadding = configuration.indentPadding(node, textDirection);
return BlockComponentPadding(
node: node,
padding: padding,
indentPadding: indentPadding,
child: child,
);
return child;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class _AppFlowyRichTextState extends State<AppFlowyRichText>
offset: widget.node.delta?.toPlainText().length ?? 0,
);

@override
Rect getBlockRect() {
throw UnimplementedError();
}

@override
Rect? getCursorRectInPosition(Position position) {
final textPosition = TextPosition(offset: position.offset);
Expand Down
Loading

0 comments on commit 33b18d9

Please sign in to comment.