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

fix: do not highlight inactive items on empty selection #915

Merged
merged 1 commit into from
Oct 9, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ ToolbarItem buildHighlightColorItem({List<ColorOption>? colorOptions}) {
final selection = editorState.selection!;
final nodes = editorState.getNodesInSelection(selection);
final isHighlight = nodes.allSatisfyInSelection(selection, (delta) {
if (delta.everyAttributes((attr) => attr.isEmpty)) {
return false;
}

return delta.everyAttributes((attributes) {
highlightColorHex = attributes[AppFlowyRichTextKeys.backgroundColor];
return highlightColorHex != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ ToolbarItem buildTextColorItem({
final selection = editorState.selection!;
final nodes = editorState.getNodesInSelection(selection);
final isHighlight = nodes.allSatisfyInSelection(selection, (delta) {
return delta.everyAttributes((attributes) {
textColorHex = attributes[AppFlowyRichTextKeys.textColor];
if (delta.everyAttributes((attr) => attr.isEmpty)) {
return false;
}

return delta.everyAttributes((attr) {
textColorHex = attr[AppFlowyRichTextKeys.textColor];
return (textColorHex != null);
});
});
Expand Down
11 changes: 6 additions & 5 deletions lib/src/editor/toolbar/desktop/items/format_toolbar_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ class _FormatToolbarItem extends ToolbarItem {
) {
final selection = editorState.selection!;
final nodes = editorState.getNodesInSelection(selection);
final isHighlight = nodes.allSatisfyInSelection(selection, (delta) {
return delta.everyAttributes(
(attributes) => attributes[name] == true,
);
});
final isHighlight = nodes.allSatisfyInSelection(
selection,
(delta) =>
delta.isNotEmpty &&
delta.everyAttributes((attr) => attr[name] == true),
);

final child = SVGIconItemWidget(
iconName: 'toolbar/$name',
Expand Down
6 changes: 3 additions & 3 deletions lib/src/render/toolbar/toolbar_item.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;

import 'package:appflowy_editor/appflowy_editor.dart';

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you use a different formatter than I do. Every time I format the code, these imports will be reverted.

Copy link
Collaborator Author

@Xazin Xazin Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use this extension https://marketplace.visualstudio.com/items?itemName=aziznal.dart-import-sorter for cleaner imports, makes them easier to read in my opinion.

I don't think it matters much that we keep changing them, what I don't understand is why the built-in formatter is so fond of changing it back 😂.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Dart VSCode extension, I think you have a command "Organize imports", can you try using it and see if it produces same result?

typedef ToolbarItemEventHandler = void Function(
EditorState editorState,
BuildContext context,
Expand Down Expand Up @@ -102,7 +103,6 @@ bool onlyShowInTextType(EditorState editorState) {
}
final nodes = editorState.getNodesInSelection(selection);
return nodes.every(
(element) =>
element.delta != null && toolbarItemWhiteList.contains(element.type),
(node) => node.delta != null && toolbarItemWhiteList.contains(node.type),
);
}
Loading