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

This commit is contained in:
Richard Shiue 2024-11-18 16:52:51 +03:00 committed by GitHub
parent 9c22bb4fed
commit df7fe9750d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 26 additions and 21 deletions

View File

@ -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,
);
}

View File

@ -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,
);
}

View File

@ -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),
);
}

View File

@ -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"

View File

@ -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: