Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize text span decorator #290

Merged
merged 1 commit into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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