mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-11-03 03:24:08 +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);
|
super.didUpdateWidget(oldWidget);
|
||||||
|
|
||||||
if (oldWidget.markdown != widget.markdown) {
|
if (oldWidget.markdown != widget.markdown) {
|
||||||
editorState.dispose();
|
final editorState = _parseMarkdown(
|
||||||
editorState = _parseMarkdown(widget.markdown.trim());
|
widget.markdown.trim(),
|
||||||
|
previousDocument: this.editorState.document,
|
||||||
|
);
|
||||||
|
this.editorState.dispose();
|
||||||
|
this.editorState = editorState;
|
||||||
scrollController.dispose();
|
scrollController.dispose();
|
||||||
scrollController = EditorScrollController(
|
scrollController = EditorScrollController(
|
||||||
editorState: editorState,
|
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 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);
|
final editorState = EditorState(document: document);
|
||||||
return editorState;
|
return editorState;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,9 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:universal_platform/universal_platform.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(
|
typedef QuoteBlockIconBuilder = Widget Function(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
Node node,
|
Node node,
|
||||||
@ -115,7 +118,9 @@ class _QuoteBlockComponentWidgetState extends State<QuoteBlockComponentWidget>
|
|||||||
@override
|
@override
|
||||||
Node get node => widget.node;
|
Node get node => widget.node;
|
||||||
|
|
||||||
ValueNotifier<double> quoteBlockHeightNotifier = ValueNotifier(0);
|
late ValueNotifier<double> quoteBlockHeightNotifier = ValueNotifier(
|
||||||
|
_quoteBlockHeightCache[node.id] ?? 0,
|
||||||
|
);
|
||||||
|
|
||||||
StreamSubscription<EditorTransactionValue>? _transactionSubscription;
|
StreamSubscription<EditorTransactionValue>? _transactionSubscription;
|
||||||
|
|
||||||
@ -266,17 +271,19 @@ class _QuoteBlockComponentWidgetState extends State<QuoteBlockComponentWidget>
|
|||||||
void _updateQuoteBlockHeight() {
|
void _updateQuoteBlockHeight() {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||||
final renderObject = layoutBuilderKey.currentContext?.findRenderObject();
|
final renderObject = layoutBuilderKey.currentContext?.findRenderObject();
|
||||||
|
double height = _quoteBlockHeightCache[node.id] ?? 0;
|
||||||
if (renderObject != null && renderObject is RenderBox) {
|
if (renderObject != null && renderObject is RenderBox) {
|
||||||
if (UniversalPlatform.isMobile) {
|
if (UniversalPlatform.isMobile) {
|
||||||
quoteBlockHeightNotifier.value =
|
height = renderObject.size.height - padding.top;
|
||||||
renderObject.size.height - padding.top;
|
|
||||||
} else {
|
} else {
|
||||||
quoteBlockHeightNotifier.value =
|
height = renderObject.size.height - padding.top * 2;
|
||||||
renderObject.size.height - padding.top * 2;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
quoteBlockHeightNotifier.value = 0;
|
height = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quoteBlockHeightNotifier.value = height;
|
||||||
|
_quoteBlockHeightCache[node.id] = height;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,8 +90,8 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: ec7350d
|
ref: "5070212"
|
||||||
resolved-ref: ec7350da7c298639c85e88229033da0c8aae8578
|
resolved-ref: "5070212ee0f02182a8acdd760b4d7b42264baec4"
|
||||||
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
|
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
|
||||||
source: git
|
source: git
|
||||||
version: "5.1.0"
|
version: "5.1.0"
|
||||||
|
|||||||
@ -180,7 +180,7 @@ dependency_overrides:
|
|||||||
appflowy_editor:
|
appflowy_editor:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/AppFlowy-IO/appflowy-editor.git
|
url: https://github.com/AppFlowy-IO/appflowy-editor.git
|
||||||
ref: "ec7350d"
|
ref: "5070212"
|
||||||
|
|
||||||
appflowy_editor_plugins:
|
appflowy_editor_plugins:
|
||||||
git:
|
git:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user