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.

chore: bump table column width when saving chat message to page (#7243)

Richard Shiuecfe481759f9e
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_edit_document_service.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_edit_document_service.dart
index c0936b5b75..630feb379b 100644
--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_edit_document_service.dart
+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/application/chat_edit_document_service.dart
@@ -31,7 +31,10 @@ class ChatEditDocumentService {
return null;
}
- final document = customMarkdownToDocument(completeMessage);
+ final document = customMarkdownToDocument(
+ completeMessage,
+ tableWidth: 250.0,
+ );
final initialBytes =
DocumentDataPBFromTo.fromDocument(document)?.writeToBuffer();
if (initialBytes == null) {
@@ -72,7 +75,10 @@ class ChatEditDocumentService {
return;
}
- final messageDocument = customMarkdownToDocument(completeMessage);
+ final messageDocument = customMarkdownToDocument(
+ completeMessage,
+ tableWidth: 250.0,
+ );
if (messageDocument.isEmpty) {
Log.error('Failed to convert message to document');
return;
diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart
index 6a1f897ee6..79a4868a9f 100644
--- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart
+++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_message_action_bar.dart
@@ -164,7 +164,10 @@ class CopyButton extends StatelessWidget {
size: const Size.square(16),
),
onPressed: () async {
- final document = customMarkdownToDocument(textMessage.text);
+ final document = customMarkdownToDocument(
+ textMessage.text,
+ tableWidth: 250.0,
+ );
await getIt<ClipboardService>().setData(
ClipboardServiceData(
plainText: textMessage.text,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/parsers/markdown_simple_table_parser.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/parsers/markdown_simple_table_parser.dart
index 47668ec0ff..a857d1ca8f 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/parsers/markdown_simple_table_parser.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/parsers/markdown_simple_table_parser.dart
@@ -1,9 +1,14 @@
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:markdown/markdown.dart' as md;
+import 'package:universal_platform/universal_platform.dart';
class MarkdownSimpleTableParser extends CustomMarkdownParser {
- const MarkdownSimpleTableParser();
+ const MarkdownSimpleTableParser({
+ this.tableWidth,
+ });
+
+ final double? tableWidth;
@override
List<Node> transform(
@@ -98,6 +103,13 @@ class MarkdownSimpleTableParser extends CustomMarkdownParser {
);
}
- return [simpleTableBlockNode(children: rows)];
+ return [
+ simpleTableBlockNode(
+ children: rows,
+ columnWidths: UniversalPlatform.isMobile || tableWidth == null
+ ? null
+ : {for (var i = 0; i < th.length; i++) i.toString(): tableWidth!},
+ ),
+ ];
}
}
diff --git a/frontend/appflowy_flutter/lib/shared/markdown_to_document.dart b/frontend/appflowy_flutter/lib/shared/markdown_to_document.dart
index b3e2034602..5763906b57 100644
--- a/frontend/appflowy_flutter/lib/shared/markdown_to_document.dart
+++ b/frontend/appflowy_flutter/lib/shared/markdown_to_document.dart
@@ -1,12 +1,15 @@
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
-Document customMarkdownToDocument(String markdown) {
+Document customMarkdownToDocument(
+ String markdown, {
+ double? tableWidth,
+}) {
return markdownToDocument(
markdown,
markdownParsers: [
const MarkdownCodeBlockParser(),
- const MarkdownSimpleTableParser(),
+ MarkdownSimpleTableParser(tableWidth: tableWidth),
],
);
}
diff --git a/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_markdown_test.dart b/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_markdown_test.dart
index 4037958873..354e6bfa5e 100644
--- a/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_markdown_test.dart
+++ b/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_markdown_test.dart
@@ -49,6 +49,21 @@ void main() {
expect(tableNode.rowLength, equals(4));
expect(tableNode.columnLength, equals(4));
});
+
+ test('convert markdown to simple table (2)', () async {
+ final document = customMarkdownToDocument(
+ _sampleMarkdown1,
+ tableWidth: 200,
+ );
+ expect(document, isNotNull);
+ final tableNode = document.nodeAtPath([0])!;
+ expect(tableNode, isNotNull);
+ expect(tableNode.type, equals(SimpleTableBlockKeys.type));
+ expect(tableNode.columnWidths.length, 4);
+ for (final entry in tableNode.columnWidths.entries) {
+ expect(entry.value, equals(200));
+ }
+ });
});
}