From f4cf5d0808f66383864e788a5cd6193cebfa124d Mon Sep 17 00:00:00 2001 From: Sean Riley Hawkins <42723553+rileyhawk1417@users.noreply.github.com> Date: Mon, 12 Sep 2022 14:10:48 +0200 Subject: [PATCH] Feat embed code (#985) * fix: fix linux build * Merge pull request #599 from AppFlowy-IO/refactor/grid_decode_cell_data Refactor/grid decode cell data * refactor: cleaned up and added bold, italic styles * refactor: remove bold & italic styles Co-authored-by: Nathan.fooo <86001920+appflowy@users.noreply.github.com> --- .../src/render/rich_text/rich_text_style.dart | 5 ++++- .../lib/src/render/toolbar/toolbar_item.dart | 16 ++++++++++++++++ .../format_rich_text_style.dart | 4 ++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/rich_text_style.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/rich_text_style.dart index 2cd03fe389..5140e70daf 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/rich_text_style.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/rich_text_style.dart @@ -255,6 +255,9 @@ class RichTextStyle { if (attributes.href != null) { return Colors.lightBlue; } + if (attributes.code) { + return Colors.lightBlue.withOpacity(0.8); + } return attributes.color ?? Colors.black; } @@ -262,7 +265,7 @@ class RichTextStyle { if (attributes.backgroundColor != null) { return attributes.backgroundColor!; } else if (attributes.code) { - return Colors.grey.withOpacity(0.4); + return Colors.blue.shade300.withOpacity(0.3); } return null; } diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart index ff94dfc111..1b028abf50 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart @@ -172,6 +172,22 @@ List defaultToolbarItems = [ ), handler: (editorState, context) => formatStrikethrough(editorState), ), + ToolbarItem( + id: 'appflowy.toolbar.code', + type: 2, + tooltipsMessage: 'Embed Code', + iconBuilder: (isHighlight) => FlowySvg( + name: 'toolbar/code', + color: isHighlight ? Colors.lightBlue : null, + ), + validator: _showInTextSelection, + highlightCallback: (editorState) => _allSatisfy( + editorState, + StyleKey.code, + (value) => value == StyleKey.code, + ), + handler: (editorState, context) => formatEmbedCode(editorState), + ), ToolbarItem( id: 'appflowy.toolbar.quote', type: 3, diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart index 038f3119af..b832f149b1 100644 --- a/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart +++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/service/default_text_operations/format_rich_text_style.dart @@ -139,6 +139,10 @@ bool formatStrikethrough(EditorState editorState) { return formatRichTextPartialStyle(editorState, StyleKey.strikethrough); } +bool formatEmbedCode(EditorState editorState) { + return formatRichTextPartialStyle(editorState, StyleKey.code); +} + bool formatHighlight(EditorState editorState) { bool value = _allSatisfyInSelection( editorState, StyleKey.backgroundColor, defaultHighlightColor);