diff --git a/lib/src/editor/selection_menu/selection_menu_item_widget.dart b/lib/src/editor/selection_menu/selection_menu_item_widget.dart index 4fb4a6ffc..7c79440fd 100644 --- a/lib/src/editor/selection_menu/selection_menu_item_widget.dart +++ b/lib/src/editor/selection_menu/selection_menu_item_widget.dart @@ -1,6 +1,6 @@ -import 'package:appflowy_editor/src/editor_state.dart'; import 'package:appflowy_editor/src/editor/selection_menu/selection_menu_service.dart'; import 'package:appflowy_editor/src/editor/selection_menu/selection_menu_widget.dart'; +import 'package:appflowy_editor/src/editor_state.dart'; import 'package:flutter/material.dart'; class SelectionMenuItemWidget extends StatefulWidget { @@ -32,6 +32,7 @@ class _SelectionMenuItemWidgetState extends State { @override Widget build(BuildContext context) { final style = widget.selectionMenuStyle; + final isSelected = widget.isSelected || _onHover; return Container( padding: const EdgeInsets.fromLTRB(8.0, 5.0, 8.0, 5.0), child: SizedBox( @@ -53,16 +54,18 @@ class _SelectionMenuItemWidgetState extends State { ) : WidgetStateProperty.all(Colors.transparent), ), - label: Text( - widget.item.name, - textAlign: TextAlign.left, - style: TextStyle( - color: (widget.isSelected || _onHover) - ? style.selectionMenuItemSelectedTextColor - : style.selectionMenuItemTextColor, - fontSize: 12.0, - ), - ), + label: widget.item.nameBuilder + ?.call(widget.item.name, style, isSelected) ?? + Text( + widget.item.name, + textAlign: TextAlign.left, + style: TextStyle( + color: (widget.isSelected || _onHover) + ? style.selectionMenuItemSelectedTextColor + : style.selectionMenuItemTextColor, + fontSize: 12.0, + ), + ), onPressed: () { widget.item.handler( widget.editorState, diff --git a/lib/src/editor/selection_menu/selection_menu_widget.dart b/lib/src/editor/selection_menu/selection_menu_widget.dart index baa72a52e..05a5857a9 100644 --- a/lib/src/editor/selection_menu/selection_menu_widget.dart +++ b/lib/src/editor/selection_menu/selection_menu_widget.dart @@ -11,6 +11,12 @@ typedef SelectionMenuItemHandler = void Function( BuildContext context, ); +typedef SelectionMenuItemNameBuilder = Widget Function( + String name, + SelectionMenuStyle style, + bool isSelected, +); + /// Selection Menu Item class SelectionMenuItem { SelectionMenuItem({ @@ -18,6 +24,7 @@ class SelectionMenuItem { required this.icon, required this.keywords, required SelectionMenuItemHandler handler, + this.nameBuilder, }) : _getName = getName { this.handler = (editorState, menuService, context) { if (deleteSlash) { @@ -35,6 +42,7 @@ class SelectionMenuItem { bool onSelected, SelectionMenuStyle style, ) icon; + final SelectionMenuItemNameBuilder? nameBuilder; String get name => _getName(); @@ -94,6 +102,7 @@ class SelectionMenuItem { bool onSelected, SelectionMenuStyle style, )? iconBuilder, + SelectionMenuItemNameBuilder? nameBuilder, bool Function(EditorState editorState, Node node)? insertBefore, bool Function(EditorState editorState, Node node)? replace, Selection? Function( @@ -109,6 +118,7 @@ class SelectionMenuItem { return SelectionMenuItem( getName: getName, + nameBuilder: nameBuilder, icon: (editorState, onSelected, style) { if (iconData != null) { return Icon( @@ -217,6 +227,7 @@ class SelectionMenuWidget extends StatefulWidget { required this.itemCountFilter, required this.deleteSlashByDefault, this.singleColumn = false, + this.nameBuilder, }); final List items; @@ -234,6 +245,8 @@ class SelectionMenuWidget extends StatefulWidget { final bool deleteSlashByDefault; final bool singleColumn; + final SelectionMenuItemNameBuilder? nameBuilder; + @override State createState() => _SelectionMenuWidgetState(); }