-
Notifications
You must be signed in to change notification settings - Fork 198
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
Feat: customized color options #270
Merged
LucasXu0
merged 6 commits into
AppFlowy-IO:main
from
hyj1204:feat/customized_color_options
Jul 4, 2023
+131
−385
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
20d9822
feat: make color options customized
hyj1204 25f1daf
chore: update color options in simple editor
hyj1204 cdad6df
chore: update tests cases
hyj1204 442a57c
chore: remove color options from mobile toolbar
hyj1204 afa0d4a
fix: fix selected color issue
hyj1204 e352564
fix: fix reset color issue
hyj1204 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 33 additions & 29 deletions
62
lib/src/editor/toolbar/desktop/items/color/highlight_color_toolbar_item.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
import 'package:appflowy_editor/appflowy_editor.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
final highlightColorItem = ToolbarItem( | ||
id: 'editor.highlightColor', | ||
group: 4, | ||
isActive: onlyShowInTextType, | ||
builder: (context, editorState) { | ||
String? highlightColorHex; | ||
ToolbarItem buildHighlightColorItem({List<ColorOption>? colorOptions}) { | ||
return ToolbarItem( | ||
id: 'editor.highlightColor', | ||
group: 4, | ||
isActive: onlyShowInTextType, | ||
builder: (context, editorState) { | ||
String? highlightColorHex; | ||
|
||
final selection = editorState.selection!; | ||
final nodes = editorState.getNodesInSelection(selection); | ||
final isHighlight = nodes.allSatisfyInSelection(selection, (delta) { | ||
return delta.everyAttributes( | ||
(attributes) => attributes[FlowyRichTextKeys.highlightColor] != null, | ||
final selection = editorState.selection!; | ||
final nodes = editorState.getNodesInSelection(selection); | ||
final isHighlight = nodes.allSatisfyInSelection(selection, (delta) { | ||
return delta.everyAttributes((attributes) { | ||
highlightColorHex = attributes[FlowyRichTextKeys.highlightColor]; | ||
return highlightColorHex != null; | ||
}); | ||
}); | ||
return IconItemWidget( | ||
iconName: 'toolbar/highlight_color', | ||
iconSize: const Size.square(14), | ||
isHighlight: isHighlight, | ||
tooltip: AppFlowyEditorLocalizations.current.highlightColor, | ||
onPressed: () { | ||
showColorMenu( | ||
context, | ||
editorState, | ||
selection, | ||
currentColorHex: highlightColorHex, | ||
isTextColor: false, | ||
highlightColorOptions: colorOptions, | ||
); | ||
}, | ||
); | ||
}); | ||
return IconItemWidget( | ||
iconName: 'toolbar/highlight_color', | ||
iconSize: const Size.square(14), | ||
isHighlight: isHighlight, | ||
tooltip: AppFlowyEditorLocalizations.current.highlightColor, | ||
onPressed: () { | ||
showColorMenu( | ||
context, | ||
editorState, | ||
selection, | ||
currentColorHex: highlightColorHex, | ||
isTextColor: false, | ||
); | ||
}, | ||
); | ||
}, | ||
); | ||
}, | ||
); | ||
} |
64 changes: 35 additions & 29 deletions
64
lib/src/editor/toolbar/desktop/items/color/text_color_toolbar_item.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
import 'package:appflowy_editor/appflowy_editor.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
final textColorItem = ToolbarItem( | ||
id: 'editor.textColor', | ||
group: 4, | ||
isActive: onlyShowInTextType, | ||
builder: (context, editorState) { | ||
String? textColorHex; | ||
final selection = editorState.selection!; | ||
final nodes = editorState.getNodesInSelection(selection); | ||
final isHighlight = nodes.allSatisfyInSelection(selection, (delta) { | ||
return delta.everyAttributes( | ||
(attributes) => attributes[FlowyRichTextKeys.textColor] != null, | ||
ToolbarItem buildTextColorItem({ | ||
List<ColorOption>? colorOptions, | ||
}) { | ||
return ToolbarItem( | ||
id: 'editor.textColor', | ||
group: 4, | ||
isActive: onlyShowInTextType, | ||
builder: (context, editorState) { | ||
String? textColorHex; | ||
final selection = editorState.selection!; | ||
final nodes = editorState.getNodesInSelection(selection); | ||
final isHighlight = nodes.allSatisfyInSelection(selection, (delta) { | ||
return delta.everyAttributes((attributes) { | ||
textColorHex = attributes[FlowyRichTextKeys.textColor]; | ||
return (textColorHex != null); | ||
}); | ||
}); | ||
return IconItemWidget( | ||
iconName: 'toolbar/text_color', | ||
isHighlight: isHighlight, | ||
iconSize: const Size.square(14), | ||
tooltip: AppFlowyEditorLocalizations.current.textColor, | ||
onPressed: () { | ||
showColorMenu( | ||
context, | ||
editorState, | ||
selection, | ||
currentColorHex: textColorHex, | ||
isTextColor: true, | ||
textColorOptions: colorOptions, | ||
); | ||
}, | ||
); | ||
}); | ||
return IconItemWidget( | ||
iconName: 'toolbar/text_color', | ||
isHighlight: isHighlight, | ||
iconSize: const Size.square(14), | ||
tooltip: AppFlowyEditorLocalizations.current.textColor, | ||
onPressed: () { | ||
showColorMenu( | ||
context, | ||
editorState, | ||
selection, | ||
currentColorHex: textColorHex, | ||
isTextColor: true, | ||
); | ||
}, | ||
); | ||
}, | ||
); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this ever get assigned any other value than null? Seems redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
highlightColorHex
is used to show a checked mark on current color options(if it has a color), I assigned value to it now(same with text color).Nice catch, Thanks!