fix: on ui event reset selection type (#555)

* fix: on ui event reset selection type

* test: add test
This commit is contained in:
Mathias Mogensen 2023-10-30 04:20:42 +01:00 • committed by GitHub
commit 7336274ff9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 37 deletions

View file

@ -439,43 +439,6 @@ class _DesktopSelectionServiceWidgetState
return min.clamp(start, end); return min.clamp(start, end);
} }
/*void _showDebugLayerIfNeeded() {
remove false to show debug overlay.
if (kDebugMode && false) {
_debugOverlay?.remove();
if (offset != null) {
_debugOverlay = OverlayEntry(
builder: (context) => Positioned.fromRect(
rect: Rect.fromPoints(offset, offset.translate(20, 20)),
child: Container(
color: Colors.red.withOpacity(0.2),
),
),
);
Overlay.of(context)?.insert(_debugOverlay!);
} else if (_panStartOffset != null) {
_debugOverlay = OverlayEntry(
builder: (context) => Positioned.fromRect(
rect: Rect.fromPoints(
_panStartOffset?.translate(
0,
-(editorState.service.scrollService!.dy -
_panStartScrollDy!),
) ??
Offset.zero,
offset ?? Offset.zero),
child: Container(
color: Colors.red.withOpacity(0.2),
),
),
);
Overlay.of(context)?.insert(_debugOverlay!);
} else {
_debugOverlay = null;
}
}
}*/
@override @override
void registerGestureInterceptor(SelectionGestureInterceptor interceptor) { void registerGestureInterceptor(SelectionGestureInterceptor interceptor) {
_interceptors.add(interceptor); _interceptors.add(interceptor);

View file

@ -200,6 +200,7 @@ class EditorState {
final completer = Completer<void>(); final completer = Completer<void>();
if (reason == SelectionUpdateReason.uiEvent) { if (reason == SelectionUpdateReason.uiEvent) {
selectionType = SelectionType.inline;
WidgetsBinding.instance.addPostFrameCallback( WidgetsBinding.instance.addPostFrameCallback(
(timeStamp) => completer.complete(), (timeStamp) => completer.complete(),
); );
@ -208,6 +209,7 @@ class EditorState {
// broadcast to other users here // broadcast to other users here
selectionExtraInfo = extraInfo; selectionExtraInfo = extraInfo;
_selectionUpdateReason = reason; _selectionUpdateReason = reason;
this.selection = selection; this.selection = selection;
return completer.future; return completer.future;

View file

@ -160,5 +160,29 @@ void main() async {
await editor.dispose(); await editor.dispose();
}); });
testWidgets('Block selection and then single tap', (tester) async {
const text = 'Welcome to Appflowy 😁';
final editor = tester.editor..addParagraph(initialText: text);
await editor.startTesting();
final firstNode = editor.nodeAtPath([0]);
final finder = find.byKey(firstNode!.key);
final rect = tester.getRect(finder);
editor.editorState.selectionType = SelectionType.block;
// tap at the beginning
await tester.tapAt(rect.centerLeft);
expect(
editor.selection,
Selection.single(path: [0], startOffset: 0),
);
expect(editor.editorState.selectionType, SelectionType.inline);
await editor.dispose();
});
}); });
} }