Browse Source

feat: disable scroll when showing popuplist

Lucas.Xu 2 năm trước cách đây
mục cha
commit
27ea5a11a9

+ 11 - 3
frontend/app_flowy/packages/flowy_editor/lib/service/internal_key_event_handlers/slash_handler.dart

@@ -106,13 +106,19 @@ void showPopupList(
       .removeListener(clearPopupList);
   editorState.service.selectionService.currentSelection
       .addListener(clearPopupList);
+
+  editorState.service.scrollService?.disable();
 }
 
 void clearPopupList() {
+  if (_popupListOverlay == null || _editorState == null) {
+    return;
+  }
   _popupListOverlay?.remove();
   _popupListOverlay = null;
 
   _editorState?.service.keyboardService?.enable();
+  _editorState?.service.scrollService?.enable();
   _editorState = null;
 }
 
@@ -215,10 +221,12 @@ class _PopupListWidgetState extends State<PopupListWidget> {
         widget.items[selectedIndex].handler(widget.editorState);
         return KeyEventResult.handled;
       }
-    }
-
-    if (event.logicalKey == LogicalKeyboardKey.escape) {
+    } else if (event.logicalKey == LogicalKeyboardKey.escape) {
+      clearPopupList();
+      return KeyEventResult.handled;
+    } else if (event.logicalKey == LogicalKeyboardKey.backspace) {
       clearPopupList();
+      _deleteSlash();
       return KeyEventResult.handled;
     }
 

+ 17 - 7
frontend/app_flowy/packages/flowy_editor/lib/service/scroll_service.dart

@@ -6,7 +6,8 @@ mixin FlowyScrollService<T extends StatefulWidget> on State<T> {
 
   void scrollTo(double dy);
 
-  RenderObject? scrollRenderObject();
+  void enable();
+  void disable();
 }
 
 class FlowyScroll extends StatefulWidget {
@@ -25,6 +26,8 @@ class _FlowyScrollState extends State<FlowyScroll> with FlowyScrollService {
   final _scrollController = ScrollController();
   final _scrollViewKey = GlobalKey();
 
+  bool _scrollEnabled = true;
+
   @override
   double get dy => _scrollController.position.pixels;
 
@@ -51,15 +54,22 @@ class _FlowyScrollState extends State<FlowyScroll> with FlowyScrollService {
     );
   }
 
+  @override
+  void disable() {
+    _scrollEnabled = false;
+    debugPrint('[scroll] $_scrollEnabled');
+  }
+
+  @override
+  void enable() {
+    _scrollEnabled = true;
+    debugPrint('[scroll] $_scrollEnabled');
+  }
+
   void _onPointerSignal(PointerSignalEvent event) {
-    if (event is PointerScrollEvent) {
+    if (event is PointerScrollEvent && _scrollEnabled) {
       final dy = (_scrollController.position.pixels + event.scrollDelta.dy);
       scrollTo(dy);
     }
   }
-
-  @override
-  RenderObject? scrollRenderObject() {
-    return _scrollViewKey.currentContext?.findRenderObject();
-  }
 }

+ 1 - 0
frontend/app_flowy/packages/flowy_editor/lib/service/selection_service.dart

@@ -267,6 +267,7 @@ class _FlowySelectionState extends State<FlowySelection>
     editorState.updateCursorSelection(selection);
 
     editorState.service.keyboardService?.enable();
+    editorState.service.scrollService?.enable();
   }
 
   @override