fix: prevent remote updates from scrolling local viewport

This commit is contained in:
Nathan 2026-08-06 20:17:15 +08:00
commit a9697798f6

View file

@ -1,5 +1,7 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import '../new/infra/testable_editor.dart';
void main() async {
@ -28,5 +30,53 @@ void main() async {
expect(itemFinder, findsOneWidget);
await editor.dispose();
});
testWidgets('remote document updates do not request local auto-scroll',
(tester) async {
final editor = tester.editor;
addTearDown(() async {
await tester.pumpWidget(const SizedBox.shrink());
editor.editorState.dispose();
});
for (var i = 0; i < 3; i++) {
editor.addParagraph(initialText: 'paragraph $i');
}
await editor.startTesting();
await editor.updateSelection(
Selection.collapsed(
Position(path: [0]),
),
);
final localSelection = editor.selection;
final autoScroller = editor.editorState.autoScroller;
expect(autoScroller, isNotNull);
if (autoScroller == null) {
return;
}
autoScroller.stopAutoScroll();
expect(autoScroller.lastOffset, isNull);
final remotelyEditedNode = editor.nodeAtPath([1]);
expect(remotelyEditedNode, isNotNull);
if (remotelyEditedNode == null) {
return;
}
final transaction = editor.editorState.transaction
..updateNode(
remotelyEditedNode,
{
ParagraphBlockKeys.delta:
(Delta()..insert('updated remotely')).toJson(),
},
);
await editor.editorState.apply(transaction, isRemote: true);
await tester.pump();
expect(editor.selection, localSelection);
expect(autoScroller.lastOffset, isNull);
});
});
}