mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 14:47:13 -04:00
fix: unit test and integration test
This commit is contained in:
parent
dba8235440
commit
5b6af79dbd
4 changed files with 12 additions and 4 deletions
|
@ -72,8 +72,11 @@ extension AiWriterNodeExtension on EditorState {
|
|||
}
|
||||
}
|
||||
|
||||
// use \n\n as line break to improve the ai response
|
||||
// using \n will cause the ai response treat the text as a single line
|
||||
final markdown = await customDocumentToMarkdown(
|
||||
Document.blank()..insert([0], slicedNodes),
|
||||
lineBreak: '\n\n',
|
||||
);
|
||||
|
||||
// trim the last \n if it exists
|
||||
|
|
|
@ -424,6 +424,7 @@ class MarkdownTextRobot {
|
|||
firstMarkdownDelta != null) {
|
||||
final startIndex = selection.startIndex;
|
||||
final length = delta.length - startIndex;
|
||||
|
||||
transaction
|
||||
..deleteText(firstNode, startIndex, length)
|
||||
..insertTextDelta(firstNode, startIndex, firstMarkdownDelta);
|
||||
|
@ -439,7 +440,9 @@ class MarkdownTextRobot {
|
|||
lastMarkdownNode != null &&
|
||||
lastMarkdownDelta != null) {
|
||||
final endIndex = selection.endIndex;
|
||||
|
||||
transaction.deleteText(lastNode, 0, endIndex);
|
||||
|
||||
// if the last node is same as the first node, it means we have replaced the
|
||||
// selected text in the first node.
|
||||
if (lastMarkdownNode.id != firstMarkdownNode?.id) {
|
||||
|
@ -457,8 +460,9 @@ class MarkdownTextRobot {
|
|||
}
|
||||
|
||||
// step 4
|
||||
if (nodes.length > 2) {
|
||||
final middleNodes = nodes.skip(1).take(nodes.length - 2).toList();
|
||||
final length = nodes.length - 2;
|
||||
if (length > 0) {
|
||||
final middleNodes = nodes.skip(1).take(length).toList();
|
||||
transaction.deleteNodes(middleNodes);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ Future<String> customDocumentToMarkdown(
|
|||
Document document, {
|
||||
String path = '',
|
||||
AsyncValueSetter<Archive>? onArchive,
|
||||
String lineBreak = '',
|
||||
}) async {
|
||||
final List<Future<ArchiveFile>> fileFutures = [];
|
||||
|
||||
|
@ -41,7 +42,7 @@ Future<String> customDocumentToMarkdown(
|
|||
try {
|
||||
markdown = documentToMarkdown(
|
||||
document,
|
||||
lineBreak: '\n\n',
|
||||
lineBreak: lineBreak,
|
||||
customParsers: [
|
||||
const MathEquationNodeParser(),
|
||||
const CalloutNodeParser(),
|
||||
|
|
|
@ -375,7 +375,7 @@ void main() {
|
|||
await blocResponseFuture();
|
||||
bloc.runResponseAction(SuggestionAction.accept);
|
||||
await blocResponseFuture();
|
||||
expect(editorState.document.root.children.length, 1);
|
||||
expect(editorState.document.root.children.length, 2);
|
||||
expect(
|
||||
editorState.getNodeAtPath([0])!.delta!.toPlainText(),
|
||||
'Hello World',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue