From 06c3dbb6fd10df72e3e7c833c6e431cd0e34e0ea Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Wed, 5 Jul 2023 18:54:55 +0800 Subject: [PATCH] feat: customize the toolbar item widget --- lib/src/core/transform/transaction.dart | 7 ++++--- .../desktop/items/icon_item_widget.dart | 20 +++++++++++-------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/src/core/transform/transaction.dart b/lib/src/core/transform/transaction.dart index 21389a0ef..164483679 100644 --- a/lib/src/core/transform/transaction.dart +++ b/lib/src/core/transform/transaction.dart @@ -372,7 +372,7 @@ extension TextTransaction on Transaction { replaceText( node, selection.startIndex, - delta.length, + delta.length - selection.startIndex, texts.first, ); } else if (i == length - 1) { @@ -406,7 +406,7 @@ extension TextTransaction on Transaction { replaceText( node, selection.startIndex, - delta.length, + delta.length - selection.startIndex, texts.first, ); } else if (i == length - 1 && texts.length >= 2) { @@ -463,7 +463,7 @@ extension TextTransaction on Transaction { replaceText( nodes.first, selection.startIndex, - delta.length, + delta.length - selection.startIndex, text, ); path = path.next; @@ -538,6 +538,7 @@ extension TextTransaction on Transaction { final deltaQueue = entry.value; final composed = deltaQueue.fold(node.delta!, (p, e) => p.compose(e)); + assert(composed.every((element) => element is TextInsert)); updateNode(node, { 'delta': composed.toJson(), }); diff --git a/lib/src/editor/toolbar/desktop/items/icon_item_widget.dart b/lib/src/editor/toolbar/desktop/items/icon_item_widget.dart index cd1a5b7f5..1e3653037 100644 --- a/lib/src/editor/toolbar/desktop/items/icon_item_widget.dart +++ b/lib/src/editor/toolbar/desktop/items/icon_item_widget.dart @@ -6,7 +6,8 @@ class IconItemWidget extends StatelessWidget { super.key, this.size = const Size.square(30.0), this.iconSize = const Size.square(18.0), - required this.iconName, + this.iconName, + this.iconBuilder, required this.isHighlight, this.highlightColor = Colors.lightBlue, this.tooltip, @@ -15,7 +16,8 @@ class IconItemWidget extends StatelessWidget { final Size size; final Size iconSize; - final String iconName; + final String? iconName; + final WidgetBuilder? iconBuilder; final bool isHighlight; final Color highlightColor; final String? tooltip; @@ -23,12 +25,14 @@ class IconItemWidget extends StatelessWidget { @override Widget build(BuildContext context) { - Widget child = EditorSvg( - name: iconName, - color: isHighlight ? highlightColor : null, - width: iconSize.width, - height: iconSize.height, - ); + Widget child = iconBuilder != null + ? iconBuilder!(context) + : EditorSvg( + name: iconName, + color: isHighlight ? highlightColor : null, + width: iconSize.width, + height: iconSize.height, + ); if (onPressed != null) { child = MouseRegion( cursor: SystemMouseCursors.click,