Skip to content

Commit

Permalink
Merge pull request #534 from LucasXu0/disable_toolbar_in_code_block
Browse files Browse the repository at this point in the history
feat: disable toolbar in code block
  • Loading branch information
LucasXu0 authored Oct 12, 2023
2 parents 194fe2f + c854892 commit 7317eb9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,12 @@ class _QuoteIcon extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
constraints: const BoxConstraints(minWidth: 26, minHeight: 22),
padding: const EdgeInsets.only(right: 4.0),
child: const Center(
child: EditorSvg(
width: 20,
height: 20,
padding: EdgeInsets.only(right: 4.0),
name: 'quote',
),
child: Container(
width: 4,
color: '#00BCF0'.tryToColor(),
),
);
}
Expand Down
19 changes: 17 additions & 2 deletions lib/src/render/toolbar/toolbar_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,25 @@ class ToolbarItem {
int get hashCode => id.hashCode;
}

final Set<String> toolbarItemWhiteList = {
ParagraphBlockKeys.type,
NumberedListBlockKeys.type,
BulletedListBlockKeys.type,
QuoteBlockKeys.type,
TodoListBlockKeys.type,
HeadingBlockKeys.type,
};

bool onlyShowInSingleSelectionAndTextType(EditorState editorState) {
final selection = editorState.selection;
if (selection == null || !selection.isSingle) {
return false;
}
final node = editorState.getNodeAtPath(selection.start.path);
return node?.delta != null;
if (node == null) {
return false;
}
return node.delta != null && toolbarItemWhiteList.contains(node.type);
}

bool onlyShowInTextType(EditorState editorState) {
Expand All @@ -88,5 +100,8 @@ bool onlyShowInTextType(EditorState editorState) {
return false;
}
final nodes = editorState.getNodesInSelection(selection);
return nodes.every((element) => element.delta != null);
return nodes.every(
(element) =>
element.delta != null && toolbarItemWhiteList.contains(element.type),
);
}

0 comments on commit 7317eb9

Please sign in to comment.