diff --git a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dart b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dart index e14275ca30..1e7d428263 100644 --- a/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dart +++ b/frontend/appflowy_flutter/lib/plugins/ai_chat/presentation/message/ai_markdown_text.dart @@ -64,8 +64,12 @@ class _AppFlowyEditorMarkdownState extends State<_AppFlowyEditorMarkdown> { super.didUpdateWidget(oldWidget); if (oldWidget.markdown != widget.markdown) { - editorState.dispose(); - editorState = _parseMarkdown(widget.markdown.trim()); + final editorState = _parseMarkdown( + widget.markdown.trim(), + previousDocument: this.editorState.document, + ); + this.editorState.dispose(); + this.editorState = editorState; scrollController.dispose(); scrollController = EditorScrollController( editorState: editorState, @@ -129,8 +133,30 @@ class _AppFlowyEditorMarkdownState extends State<_AppFlowyEditorMarkdown> { ); } - EditorState _parseMarkdown(String markdown) { + EditorState _parseMarkdown( + String markdown, { + Document? previousDocument, + }) { + // merge the nodes from the previous document with the new document to keep the same node ids final document = customMarkdownToDocument(markdown); + final documentIterator = NodeIterator( + document: document, + startNode: document.root, + ); + if (previousDocument != null) { + final previousDocumentIterator = NodeIterator( + document: previousDocument, + startNode: previousDocument.root, + ); + while ( + documentIterator.moveNext() && previousDocumentIterator.moveNext()) { + final currentNode = documentIterator.current; + final previousNode = previousDocumentIterator.current; + if (currentNode.path.equals(previousNode.path)) { + currentNode.id = previousNode.id; + } + } + } final editorState = EditorState(document: document); return editorState; } diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/quote/quote_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/quote/quote_block_component.dart index 76f42c54b1..39ab2c5327 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/quote/quote_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/quote/quote_block_component.dart @@ -5,6 +5,9 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:universal_platform/universal_platform.dart'; +/// In memory cache of the quote block height to avoid flashing when the quote block is updated. +Map _quoteBlockHeightCache = {}; + typedef QuoteBlockIconBuilder = Widget Function( BuildContext context, Node node, @@ -115,7 +118,9 @@ class _QuoteBlockComponentWidgetState extends State @override Node get node => widget.node; - ValueNotifier quoteBlockHeightNotifier = ValueNotifier(0); + late ValueNotifier quoteBlockHeightNotifier = ValueNotifier( + _quoteBlockHeightCache[node.id] ?? 0, + ); StreamSubscription? _transactionSubscription; @@ -266,17 +271,19 @@ class _QuoteBlockComponentWidgetState extends State void _updateQuoteBlockHeight() { WidgetsBinding.instance.addPostFrameCallback((timeStamp) { final renderObject = layoutBuilderKey.currentContext?.findRenderObject(); + double height = _quoteBlockHeightCache[node.id] ?? 0; if (renderObject != null && renderObject is RenderBox) { if (UniversalPlatform.isMobile) { - quoteBlockHeightNotifier.value = - renderObject.size.height - padding.top; + height = renderObject.size.height - padding.top; } else { - quoteBlockHeightNotifier.value = - renderObject.size.height - padding.top * 2; + height = renderObject.size.height - padding.top * 2; } } else { - quoteBlockHeightNotifier.value = 0; + height = 0; } + + quoteBlockHeightNotifier.value = height; + _quoteBlockHeightCache[node.id] = height; }); } } diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lock index 6a2092876c..4d580a4fd9 100644 --- a/frontend/appflowy_flutter/pubspec.lock +++ b/frontend/appflowy_flutter/pubspec.lock @@ -90,8 +90,8 @@ packages: dependency: "direct main" description: path: "." - ref: ec7350d - resolved-ref: ec7350da7c298639c85e88229033da0c8aae8578 + ref: "5070212" + resolved-ref: "5070212ee0f02182a8acdd760b4d7b42264baec4" url: "https://github.com/AppFlowy-IO/appflowy-editor.git" source: git version: "5.1.0" diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yaml index f78d776639..25ce68a289 100644 --- a/frontend/appflowy_flutter/pubspec.yaml +++ b/frontend/appflowy_flutter/pubspec.yaml @@ -180,7 +180,7 @@ dependency_overrides: appflowy_editor: git: url: https://github.com/AppFlowy-IO/appflowy-editor.git - ref: "ec7350d" + ref: "5070212" appflowy_editor_plugins: git: