Przeglądaj źródła

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 <[email protected]>
Sean Riley Hawkins 2 lat temu
rodzic
commit
f4cf5d0808

+ 4 - 1
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;
   }

+ 16 - 0
frontend/app_flowy/packages/appflowy_editor/lib/src/render/toolbar/toolbar_item.dart

@@ -172,6 +172,22 @@ List<ToolbarItem> 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,

+ 4 - 0
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);