Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

feat: wrap code block lines in AI chat (#6828)

Richard Shiuedf7fe9750d76
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_editor_style.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_editor_style.dart
index 2b4a1200b7..d138afb72f 100644
--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_editor_style.dart
+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/chat_editor_style.dart
@@ -13,6 +13,7 @@ import 'package:appflowy/workspace/application/appearance_defaults.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/appearance/base_appearance.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:collection/collection.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flutter/material.dart';
@@ -104,12 +105,18 @@ class ChatEditorStyleCustomizer extends EditorStyleCustomizer {
}
@override
- TextStyle codeBlockStyleBuilder() {
+ CodeBlockStyle codeBlockStyleBuilder() {
final fontFamily =
context.read<DocumentAppearanceCubit>().state.codeFontFamily;
- return baseTextStyle(fontFamily).copyWith(
- height: 1.4,
- color: AFThemeExtension.of(context).onBackground,
+
+ return CodeBlockStyle(
+ textStyle: baseTextStyle(fontFamily).copyWith(
+ height: 1.4,
+ color: AFThemeExtension.of(context).onBackground,
+ ),
+ backgroundColor: AFThemeExtension.of(context).calloutBGColor,
+ foregroundColor: AFThemeExtension.of(context).textColor.withAlpha(155),
+ wrapLines: true,
);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
index 0171bfc6b7..193dedb63f 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
@@ -546,18 +546,10 @@ CodeBlockComponentBuilder _buildCodeBlockComponentBuilder(
EditorStyleCustomizer styleCustomizer,
) {
return CodeBlockComponentBuilder(
- configuration: configuration.copyWith(
- textStyle: (_) => styleCustomizer.codeBlockStyleBuilder(),
- placeholderTextStyle: (_) => styleCustomizer.codeBlockStyleBuilder(),
- ),
- styleBuilder: () => CodeBlockStyle(
- backgroundColor: AFThemeExtension.of(context).calloutBGColor,
- foregroundColor: AFThemeExtension.of(context).textColor.withAlpha(155),
- ),
+ styleBuilder: styleCustomizer.codeBlockStyleBuilder,
padding: const EdgeInsets.only(left: 20, right: 30, bottom: 34),
languagePickerBuilder: codeBlockLanguagePickerBuilder,
copyButtonBuilder: codeBlockCopyBuilder,
- showLineNumbers: false,
);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
index 6e6ab845c3..003ed82ecf 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
@@ -14,6 +14,7 @@ import 'package:appflowy/workspace/application/appearance_defaults.dart';
import 'package:appflowy/workspace/application/settings/appearance/appearance_cubit.dart';
import 'package:appflowy/workspace/application/settings/appearance/base_appearance.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
@@ -194,14 +195,19 @@ class EditorStyleCustomizer {
);
}
- TextStyle codeBlockStyleBuilder() {
+ CodeBlockStyle codeBlockStyleBuilder() {
final fontSize = context.read<DocumentAppearanceCubit>().state.fontSize;
final fontFamily =
context.read<DocumentAppearanceCubit>().state.codeFontFamily;
- return baseTextStyle(fontFamily).copyWith(
- fontSize: fontSize,
- height: 1.5,
- color: AFThemeExtension.of(context).onBackground,
+
+ return CodeBlockStyle(
+ textStyle: baseTextStyle(fontFamily).copyWith(
+ fontSize: fontSize,
+ height: 1.5,
+ color: AFThemeExtension.of(context).onBackground,
+ ),
+ backgroundColor: AFThemeExtension.of(context).calloutBGColor,
+ foregroundColor: AFThemeExtension.of(context).textColor.withAlpha(155),
);
}
diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lock
index f78522353d..a970d280b7 100644
--- a/frontend/appflowy_flutter/pubspec.lock
+++ b/frontend/appflowy_flutter/pubspec.lock
@@ -70,8 +70,8 @@ packages:
dependency: "direct main"
description:
path: "packages/appflowy_editor_plugins"
- ref: "2d3d4fb"
- resolved-ref: "2d3d4fb536f32cbcdf9fcd52dfe3033429666285"
+ ref: "27c898d"
+ resolved-ref: "27c898d1343f52d80444a0f469b8ee403606cf36"
url: "https://github.com/AppFlowy-IO/AppFlowy-plugins.git"
source: git
version: "0.0.6"
diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yaml
index c5dc07be7a..1df225af6d 100644
--- a/frontend/appflowy_flutter/pubspec.yaml
+++ b/frontend/appflowy_flutter/pubspec.yaml
@@ -177,7 +177,7 @@ dependency_overrides:
git:
url: https://github.com/AppFlowy-IO/AppFlowy-plugins.git
path: "packages/appflowy_editor_plugins"
- ref: "2d3d4fb"
+ ref: "27c898d"
sheet:
git: