|
@@ -8,7 +8,6 @@ import 'package:appflowy_editor/src/service/default_text_operations/format_rich_
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:rich_clipboard/rich_clipboard.dart';
|
|
|
-import 'package:appflowy_editor/src/document/built_in_attribute_keys.dart';
|
|
|
|
|
|
typedef ToolbarItemEventHandler = void Function(
|
|
|
EditorState editorState, BuildContext context);
|
|
@@ -120,7 +119,7 @@ List<ToolbarItem> defaultToolbarItems = [
|
|
|
name: 'toolbar/bold',
|
|
|
color: isHighlight ? Colors.lightBlue : null,
|
|
|
),
|
|
|
- validator: _showInTextSelection,
|
|
|
+ validator: _showInBuiltInTextSelection,
|
|
|
highlightCallback: (editorState) => _allSatisfy(
|
|
|
editorState,
|
|
|
BuiltInAttributeKey.bold,
|
|
@@ -136,7 +135,7 @@ List<ToolbarItem> defaultToolbarItems = [
|
|
|
name: 'toolbar/italic',
|
|
|
color: isHighlight ? Colors.lightBlue : null,
|
|
|
),
|
|
|
- validator: _showInTextSelection,
|
|
|
+ validator: _showInBuiltInTextSelection,
|
|
|
highlightCallback: (editorState) => _allSatisfy(
|
|
|
editorState,
|
|
|
BuiltInAttributeKey.italic,
|
|
@@ -152,7 +151,7 @@ List<ToolbarItem> defaultToolbarItems = [
|
|
|
name: 'toolbar/underline',
|
|
|
color: isHighlight ? Colors.lightBlue : null,
|
|
|
),
|
|
|
- validator: _showInTextSelection,
|
|
|
+ validator: _showInBuiltInTextSelection,
|
|
|
highlightCallback: (editorState) => _allSatisfy(
|
|
|
editorState,
|
|
|
BuiltInAttributeKey.underline,
|
|
@@ -168,7 +167,7 @@ List<ToolbarItem> defaultToolbarItems = [
|
|
|
name: 'toolbar/strikethrough',
|
|
|
color: isHighlight ? Colors.lightBlue : null,
|
|
|
),
|
|
|
- validator: _showInTextSelection,
|
|
|
+ validator: _showInBuiltInTextSelection,
|
|
|
highlightCallback: (editorState) => _allSatisfy(
|
|
|
editorState,
|
|
|
BuiltInAttributeKey.strikethrough,
|
|
@@ -184,7 +183,7 @@ List<ToolbarItem> defaultToolbarItems = [
|
|
|
name: 'toolbar/code',
|
|
|
color: isHighlight ? Colors.lightBlue : null,
|
|
|
),
|
|
|
- validator: _showInTextSelection,
|
|
|
+ validator: _showInBuiltInTextSelection,
|
|
|
highlightCallback: (editorState) => _allSatisfy(
|
|
|
editorState,
|
|
|
BuiltInAttributeKey.code,
|
|
@@ -248,7 +247,7 @@ List<ToolbarItem> defaultToolbarItems = [
|
|
|
name: 'toolbar/highlight',
|
|
|
color: isHighlight ? Colors.lightBlue : null,
|
|
|
),
|
|
|
- validator: _showInTextSelection,
|
|
|
+ validator: _showInBuiltInTextSelection,
|
|
|
highlightCallback: (editorState) => _allSatisfy(
|
|
|
editorState,
|
|
|
BuiltInAttributeKey.backgroundColor,
|
|
@@ -262,13 +261,22 @@ List<ToolbarItem> defaultToolbarItems = [
|
|
|
];
|
|
|
|
|
|
ToolbarItemValidator _onlyShowInSingleTextSelection = (editorState) {
|
|
|
+ final result = _showInBuiltInTextSelection(editorState);
|
|
|
+ if (!result) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
final nodes = editorState.service.selectionService.currentSelectedNodes;
|
|
|
return (nodes.length == 1 && nodes.first is TextNode);
|
|
|
};
|
|
|
|
|
|
-ToolbarItemValidator _showInTextSelection = (editorState) {
|
|
|
+ToolbarItemValidator _showInBuiltInTextSelection = (editorState) {
|
|
|
final nodes = editorState.service.selectionService.currentSelectedNodes
|
|
|
- .whereType<TextNode>();
|
|
|
+ .whereType<TextNode>()
|
|
|
+ .where(
|
|
|
+ (textNode) =>
|
|
|
+ BuiltInAttributeKey.globalStyleKeys.contains(textNode.subtype) ||
|
|
|
+ textNode.subtype == null,
|
|
|
+ );
|
|
|
return nodes.isNotEmpty;
|
|
|
};
|
|
|
|