Merge branch 'main' into stable

This commit is contained in:
Lucas.Xu 2023-11-08 14:24:39 +08:00
commit db4057dea2
3 changed files with 49 additions and 30 deletions

View file

@ -15,15 +15,23 @@ Node dividerNode() {
); );
} }
typedef DividerBlockWrapper = Widget Function(
BuildContext context,
Node node,
Widget child,
);
class DividerBlockComponentBuilder extends BlockComponentBuilder { class DividerBlockComponentBuilder extends BlockComponentBuilder {
DividerBlockComponentBuilder({ DividerBlockComponentBuilder({
super.configuration, super.configuration,
this.lineColor = Colors.grey, this.lineColor = Colors.grey,
this.height = 10, this.height = 10,
this.wrapper,
}); });
final Color lineColor; final Color lineColor;
final double height; final double height;
final DividerBlockWrapper? wrapper;
@override @override
BlockComponentWidget build(BlockComponentContext blockComponentContext) { BlockComponentWidget build(BlockComponentContext blockComponentContext) {
@ -34,6 +42,7 @@ class DividerBlockComponentBuilder extends BlockComponentBuilder {
configuration: configuration, configuration: configuration,
lineColor: lineColor, lineColor: lineColor,
height: height, height: height,
wrapper: wrapper,
showActions: showActions(node), showActions: showActions(node),
actionBuilder: (context, state) => actionBuilder( actionBuilder: (context, state) => actionBuilder(
blockComponentContext, blockComponentContext,
@ -55,10 +64,12 @@ class DividerBlockComponentWidget extends BlockComponentStatefulWidget {
super.configuration = const BlockComponentConfiguration(), super.configuration = const BlockComponentConfiguration(),
this.lineColor = Colors.grey, this.lineColor = Colors.grey,
this.height = 10, this.height = 10,
this.wrapper,
}); });
final Color lineColor; final Color lineColor;
final double height; final double height;
final DividerBlockWrapper? wrapper;
@override @override
State<DividerBlockComponentWidget> createState() => State<DividerBlockComponentWidget> createState() =>
@ -119,6 +130,10 @@ class _DividerBlockComponentWidgetState
); );
} }
if (widget.wrapper != null) {
child = widget.wrapper!(context, node, child);
}
return child; return child;
} }

View file

@ -52,7 +52,8 @@ class MobileToolbar extends StatelessWidget {
if (selection == null) { if (selection == null) {
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
return MobileToolbarStyle( return RepaintBoundary(
child: MobileToolbarStyle(
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
foregroundColor: foregroundColor, foregroundColor: foregroundColor,
clearDiagonalLineColor: clearDiagonalLineColor, clearDiagonalLineColor: clearDiagonalLineColor,
@ -76,6 +77,7 @@ class MobileToolbar extends StatelessWidget {
selection: selection, selection: selection,
toolbarItems: toolbarItems, toolbarItems: toolbarItems,
), ),
),
); );
}, },
); );

View file

@ -4,6 +4,8 @@ import 'package:flutter_test/flutter_test.dart';
import '../../../infra/testable_editor.dart'; import '../../../infra/testable_editor.dart';
const _padding = 24.0;
void main() async { void main() async {
group('indentCommand - widget test indent padding', () { group('indentCommand - widget test indent padding', () {
testWidgets("indent LTR line under LTR line", (tester) async { testWidgets("indent LTR line under LTR line", (tester) async {
@ -17,7 +19,7 @@ void main() async {
final nestedBlock = node.key.currentState! final nestedBlock = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>(); .unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();
expect(nestedBlock?.indentPadding.left, 24); expect(nestedBlock?.indentPadding.left, _padding);
expect(nestedBlock?.indentPadding.right, 0); expect(nestedBlock?.indentPadding.right, 0);
await editor.dispose(); await editor.dispose();
@ -34,7 +36,7 @@ void main() async {
final nestedBlock = node.key.currentState! final nestedBlock = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>(); .unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();
expect(nestedBlock?.indentPadding.left, 24); expect(nestedBlock?.indentPadding.left, _padding);
expect(nestedBlock?.indentPadding.right, 0); expect(nestedBlock?.indentPadding.right, 0);
await editor.dispose(); await editor.dispose();
@ -55,7 +57,7 @@ void main() async {
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>(); .unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();
expect(nestedBlock?.indentPadding.left, 0); expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, 24); expect(nestedBlock?.indentPadding.right, _padding);
await editor.dispose(); await editor.dispose();
}); });
@ -75,7 +77,7 @@ void main() async {
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>(); .unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();
expect(nestedBlock?.indentPadding.left, 0); expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, 24); expect(nestedBlock?.indentPadding.right, _padding);
await editor.dispose(); await editor.dispose();
}); });
@ -95,7 +97,7 @@ void main() async {
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>(); .unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();
expect(nestedBlock?.indentPadding.left, 0); expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, 24); expect(nestedBlock?.indentPadding.right, _padding);
await editor.dispose(); await editor.dispose();
}); });
@ -120,7 +122,7 @@ void main() async {
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>(); .unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();
expect(nestedBlock?.indentPadding.left, 0); expect(nestedBlock?.indentPadding.left, 0);
expect(nestedBlock?.indentPadding.right, 24); expect(nestedBlock?.indentPadding.right, _padding);
final selection = Selection.single( final selection = Selection.single(
path: [0, 0], path: [0, 0],
@ -134,7 +136,7 @@ void main() async {
final nestedBlockAfter = node.key.currentState! final nestedBlockAfter = node.key.currentState!
.unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>(); .unwrapOrNull<NestedBlockComponentStatefulWidgetMixin>();
expect(nestedBlockAfter?.indentPadding.left, 24); expect(nestedBlockAfter?.indentPadding.left, _padding);
expect(nestedBlockAfter?.indentPadding.right, 0); expect(nestedBlockAfter?.indentPadding.right, 0);
await editor.dispose(); await editor.dispose();