Skip to content

Commit

Permalink
feat: customize the toolbar item widget
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Jul 5, 2023
1 parent 2ed30f3 commit 06c3dbb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
7 changes: 4 additions & 3 deletions lib/src/core/transform/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -463,7 +463,7 @@ extension TextTransaction on Transaction {
replaceText(
nodes.first,
selection.startIndex,
delta.length,
delta.length - selection.startIndex,
text,
);
path = path.next;
Expand Down Expand Up @@ -538,6 +538,7 @@ extension TextTransaction on Transaction {
final deltaQueue = entry.value;
final composed =
deltaQueue.fold<Delta>(node.delta!, (p, e) => p.compose(e));
assert(composed.every((element) => element is TextInsert));
updateNode(node, {
'delta': composed.toJson(),
});
Expand Down
20 changes: 12 additions & 8 deletions lib/src/editor/toolbar/desktop/items/icon_item_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,20 +16,23 @@ 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;
final VoidCallback? onPressed;

@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,
Expand Down

0 comments on commit 06c3dbb

Please sign in to comment.