mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-11-01 18:43:22 +00:00
fix: quote block flashes in ai chat page when generating answer (#7553)
This commit is contained in:
parent
eddb623fba
commit
6d327adb83
@ -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;
|
||||
}
|
||||
|
||||
@ -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<String, double> _quoteBlockHeightCache = {};
|
||||
|
||||
typedef QuoteBlockIconBuilder = Widget Function(
|
||||
BuildContext context,
|
||||
Node node,
|
||||
@ -115,7 +118,9 @@ class _QuoteBlockComponentWidgetState extends State<QuoteBlockComponentWidget>
|
||||
@override
|
||||
Node get node => widget.node;
|
||||
|
||||
ValueNotifier<double> quoteBlockHeightNotifier = ValueNotifier(0);
|
||||
late ValueNotifier<double> quoteBlockHeightNotifier = ValueNotifier(
|
||||
_quoteBlockHeightCache[node.id] ?? 0,
|
||||
);
|
||||
|
||||
StreamSubscription<EditorTransactionValue>? _transactionSubscription;
|
||||
|
||||
@ -266,17 +271,19 @@ class _QuoteBlockComponentWidgetState extends State<QuoteBlockComponentWidget>
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user