feat: add reset to default text color and improve text (#5)
This commit is contained in:
parent
a9b992877a
commit
8488c866b8
5 changed files with 97 additions and 63 deletions
1
assets/images/clear_highlight_color.svg
Normal file
1
assets/images/clear_highlight_color.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="48" viewBox="0 96 960 960" width="48"><path d="M757 780 316 339l164-163 225 222q44 44 69.5 101T800 622q0 39-12 81t-31 77Zm49 220L676 870q-38 31-90 48.5T480 936q-132 0-226-91.5T160 621q0-57 17-106t53-91L57 251l43-43 749 749-43 43Z" fill="white"/></svg>
|
||||||
|
After Width: | Height: | Size: 299 B |
1
assets/images/reset_text_color.svg
Normal file
1
assets/images/reset_text_color.svg
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="#FFFFFF"><path d="M0 0h24v24H0V0z" fill="none"/><path d="M14 12c0-1.1-.9-2-2-2s-2 .9-2 2 .9 2 2 2 2-.9 2-2zm-2-9c-4.97 0-9 4.03-9 9H0l4 4 4-4H5c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.51 0-2.91-.49-4.06-1.3l-1.42 1.44C8.04 20.3 9.94 21 12 21c4.97 0 9-4.03 9-9s-4.03-9-9-9z"/></svg>
|
||||||
|
After Width: | Height: | Size: 377 B |
|
|
@ -55,24 +55,11 @@ void _formatHighlightColor(EditorState editorState, String color) {
|
||||||
|
|
||||||
void _formatFontColor(EditorState editorState, String color) {
|
void _formatFontColor(EditorState editorState, String color) {
|
||||||
final selection = editorState.selection!;
|
final selection = editorState.selection!;
|
||||||
//Since there is no additional color for the text, remove the 'textColor' attribute, so that the textColor item on the toolbar won't be highlighted
|
editorState.formatDelta(selection, {'textColor': color});
|
||||||
//'0xff000000' is the deault color when developer doesn't set.
|
|
||||||
if (color == editorState.editorStyle.textStyle?.color?.toHex() ||
|
|
||||||
color == '0xff000000') {
|
|
||||||
editorState.formatDelta(selection, {'textColor': null});
|
|
||||||
} else {
|
|
||||||
editorState.formatDelta(selection, {'textColor': color});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ColorOption> _generateTextColorOptions(EditorState editorState) {
|
List<ColorOption> _generateTextColorOptions(EditorState editorState) {
|
||||||
final defaultColor = editorState.editorStyle.textStyle?.color ??
|
|
||||||
Colors.black; // the deault text color when developer doesn't set
|
|
||||||
return [
|
return [
|
||||||
ColorOption(
|
|
||||||
colorHex: defaultColor.toHex(),
|
|
||||||
name: AppFlowyEditorLocalizations.current.fontColorDefault,
|
|
||||||
),
|
|
||||||
ColorOption(
|
ColorOption(
|
||||||
colorHex: Colors.grey.toHex(),
|
colorHex: Colors.grey.toHex(),
|
||||||
name: AppFlowyEditorLocalizations.current.fontColorGray,
|
name: AppFlowyEditorLocalizations.current.fontColorGray,
|
||||||
|
|
@ -109,13 +96,7 @@ List<ColorOption> _generateTextColorOptions(EditorState editorState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ColorOption> _generateHighlightColorOptions(EditorState editorState) {
|
List<ColorOption> _generateHighlightColorOptions(EditorState editorState) {
|
||||||
final defaultBackgroundColorHex = editorState.editorStyle.highlightColorHex ??
|
|
||||||
'0x6000BCF0'; // the deault highlight color when developer doesn't set
|
|
||||||
return [
|
return [
|
||||||
ColorOption(
|
|
||||||
colorHex: defaultBackgroundColorHex,
|
|
||||||
name: AppFlowyEditorLocalizations.current.backgroundColorDefault,
|
|
||||||
),
|
|
||||||
ColorOption(
|
ColorOption(
|
||||||
colorHex: Colors.grey.withOpacity(0.3).toHex(),
|
colorHex: Colors.grey.withOpacity(0.3).toHex(),
|
||||||
name: AppFlowyEditorLocalizations.current.backgroundColorGray,
|
name: AppFlowyEditorLocalizations.current.backgroundColorGray,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:appflowy_editor/src/core/legacy/built_in_attribute_keys.dart';
|
||||||
import 'package:appflowy_editor/src/editor/command/text_commands.dart';
|
import 'package:appflowy_editor/src/editor/command/text_commands.dart';
|
||||||
import 'package:appflowy_editor/src/editor_state.dart';
|
import 'package:appflowy_editor/src/editor_state.dart';
|
||||||
import 'package:appflowy_editor/src/infra/flowy_svg.dart';
|
import 'package:appflowy_editor/src/infra/flowy_svg.dart';
|
||||||
|
|
@ -79,6 +80,13 @@ class _ColorPickerState extends State<ColorPicker> {
|
||||||
dismissOverlay: widget.onDismiss,
|
dismissOverlay: widget.onDismiss,
|
||||||
)
|
)
|
||||||
: const SizedBox.shrink(),
|
: const SizedBox.shrink(),
|
||||||
|
// set text color back to null(default text color)
|
||||||
|
widget.isTextColor == true && widget.selectedColorHex != null
|
||||||
|
? ResetTextColorButton(
|
||||||
|
editorState: widget.editorState,
|
||||||
|
dismissOverlay: widget.onDismiss,
|
||||||
|
)
|
||||||
|
: const SizedBox.shrink(),
|
||||||
CustomColorItem(
|
CustomColorItem(
|
||||||
colorController: _colorHexController,
|
colorController: _colorHexController,
|
||||||
opacityController: _colorOpacityController,
|
opacityController: _colorOpacityController,
|
||||||
|
|
@ -160,6 +168,57 @@ class _ColorPickerState extends State<ColorPicker> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ResetTextColorButton extends StatelessWidget {
|
||||||
|
const ResetTextColorButton({
|
||||||
|
super.key,
|
||||||
|
required this.editorState,
|
||||||
|
required this.dismissOverlay,
|
||||||
|
});
|
||||||
|
|
||||||
|
final EditorState editorState;
|
||||||
|
final Function() dismissOverlay;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 32,
|
||||||
|
child: TextButton.icon(
|
||||||
|
onPressed: () {
|
||||||
|
final selection = editorState.selection!;
|
||||||
|
editorState
|
||||||
|
.formatDelta(selection, {BuiltInAttributeKey.textColor: null});
|
||||||
|
dismissOverlay();
|
||||||
|
},
|
||||||
|
icon: FlowySvg(
|
||||||
|
name: 'reset_text_color',
|
||||||
|
width: 13,
|
||||||
|
height: 13,
|
||||||
|
color: Theme.of(context).iconTheme.color,
|
||||||
|
),
|
||||||
|
label: Text(
|
||||||
|
AppFlowyEditorLocalizations.current.resetToDefaultColor,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context).hintColor,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.left,
|
||||||
|
),
|
||||||
|
style: ButtonStyle(
|
||||||
|
backgroundColor: MaterialStateProperty.resolveWith<Color>(
|
||||||
|
(Set<MaterialState> states) {
|
||||||
|
if (states.contains(MaterialState.hovered)) {
|
||||||
|
return Theme.of(context).hoverColor;
|
||||||
|
}
|
||||||
|
return Colors.transparent;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ClearHighlightColorButton extends StatelessWidget {
|
class ClearHighlightColorButton extends StatelessWidget {
|
||||||
const ClearHighlightColorButton({
|
const ClearHighlightColorButton({
|
||||||
super.key,
|
super.key,
|
||||||
|
|
@ -178,11 +237,14 @@ class ClearHighlightColorButton extends StatelessWidget {
|
||||||
child: TextButton.icon(
|
child: TextButton.icon(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
final selection = editorState.selection!;
|
final selection = editorState.selection!;
|
||||||
editorState.formatDelta(selection, {'highlightColor': null});
|
editorState.formatDelta(
|
||||||
|
selection,
|
||||||
|
{BuiltInAttributeKey.highlightColor: null},
|
||||||
|
);
|
||||||
dismissOverlay();
|
dismissOverlay();
|
||||||
},
|
},
|
||||||
icon: FlowySvg(
|
icon: FlowySvg(
|
||||||
name: 'toolbar/clear_highlight_color',
|
name: 'clear_highlight_color',
|
||||||
width: 13,
|
width: 13,
|
||||||
height: 13,
|
height: 13,
|
||||||
color: Theme.of(context).iconTheme.color,
|
color: Theme.of(context).iconTheme.color,
|
||||||
|
|
|
||||||
|
|
@ -221,16 +221,6 @@ class AppFlowyEditorLocalizations {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Default`
|
|
||||||
String get fontColorDefault {
|
|
||||||
return Intl.message(
|
|
||||||
'Default',
|
|
||||||
name: 'fontColorDefault',
|
|
||||||
desc: '',
|
|
||||||
args: [],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `Gray`
|
/// `Gray`
|
||||||
String get fontColorGray {
|
String get fontColorGray {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
|
|
@ -321,16 +311,6 @@ class AppFlowyEditorLocalizations {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `Default background`
|
|
||||||
String get backgroundColorDefault {
|
|
||||||
return Intl.message(
|
|
||||||
'Default background',
|
|
||||||
name: 'backgroundColorDefault',
|
|
||||||
desc: '',
|
|
||||||
args: [],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `Gray background`
|
/// `Gray background`
|
||||||
String get backgroundColorGray {
|
String get backgroundColorGray {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
|
|
@ -601,101 +581,111 @@ class AppFlowyEditorLocalizations {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `text color`
|
/// `Text color`
|
||||||
String get textColor {
|
String get textColor {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'text color',
|
'Text color',
|
||||||
name: 'textColor',
|
name: 'textColor',
|
||||||
desc: '',
|
desc: '',
|
||||||
args: [],
|
args: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `add your link`
|
/// `Reset to default color`
|
||||||
|
String get resetToDefaultColor {
|
||||||
|
return Intl.message(
|
||||||
|
'Reset to default color',
|
||||||
|
name: 'resetToDefaultColor ',
|
||||||
|
desc: '',
|
||||||
|
args: [],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `Add your link`
|
||||||
String get addYourLink {
|
String get addYourLink {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'add your link',
|
'Add your link',
|
||||||
name: 'addYourLink',
|
name: 'addYourLink',
|
||||||
desc: '',
|
desc: '',
|
||||||
args: [],
|
args: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `open link`
|
/// `Open link`
|
||||||
String get openLink {
|
String get openLink {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'open link',
|
'Open link',
|
||||||
name: 'openLink',
|
name: 'openLink',
|
||||||
desc: '',
|
desc: '',
|
||||||
args: [],
|
args: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `copy link`
|
/// `Copy link`
|
||||||
String get copyLink {
|
String get copyLink {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'copy link',
|
'Copy link',
|
||||||
name: 'copyLink',
|
name: 'copyLink',
|
||||||
desc: '',
|
desc: '',
|
||||||
args: [],
|
args: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `remove link`
|
/// `Remove link`
|
||||||
String get removeLink {
|
String get removeLink {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'remove link',
|
'Remove link',
|
||||||
name: 'removeLink',
|
name: 'removeLink',
|
||||||
desc: '',
|
desc: '',
|
||||||
args: [],
|
args: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `highlight color`
|
/// `Highlight color`
|
||||||
String get highlightColor {
|
String get highlightColor {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'highlight color',
|
'Highlight color',
|
||||||
name: 'highlightColor',
|
name: 'highlightColor',
|
||||||
desc: '',
|
desc: '',
|
||||||
args: [],
|
args: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `clear highlight color`
|
/// `Clear highlight color`
|
||||||
String get clearHighlightColor {
|
String get clearHighlightColor {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'clear highlight color',
|
'Clear highlight color',
|
||||||
name: 'clearHighlightColor',
|
name: 'clearHighlightColor',
|
||||||
desc: '',
|
desc: '',
|
||||||
args: [],
|
args: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `custom color`
|
/// `Custom color`
|
||||||
String get customColor {
|
String get customColor {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'custom color',
|
'Custom color',
|
||||||
name: 'customColor',
|
name: 'customColor',
|
||||||
desc: '',
|
desc: '',
|
||||||
args: [],
|
args: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `hex value`
|
/// `Hex value`
|
||||||
String get hexValue {
|
String get hexValue {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'hex value',
|
'Hex value',
|
||||||
name: 'hexValue',
|
name: 'hexValue',
|
||||||
desc: '',
|
desc: '',
|
||||||
args: [],
|
args: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `opacity`
|
/// `Opacity`
|
||||||
String get opacity {
|
String get opacity {
|
||||||
return Intl.message(
|
return Intl.message(
|
||||||
'opacity',
|
'Opacity',
|
||||||
name: 'opacity',
|
name: 'Opacity',
|
||||||
desc: '',
|
desc: '',
|
||||||
args: [],
|
args: [],
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue