فهرست منبع

fix: pasting a link in a URL grid crashes the app

unknown 1 سال پیش
والد
کامیت
f6edd4b32b

+ 1 - 1
frontend/appflowy_flutter/.gitignore

@@ -76,4 +76,4 @@ coverage/
 
 **/failures/*.png
 
-assets/translations/*.json
+assets/translations/

+ 26 - 12
frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/accessory/cell_shortcuts.dart

@@ -1,3 +1,5 @@
+import 'dart:io';
+
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
 
@@ -22,23 +24,35 @@ class GridCellShortcuts extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     return Shortcuts(
-      shortcuts: {
-        LogicalKeySet(LogicalKeyboardKey.enter): const GridCellEnterIdent(),
-        LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyC):
-            const GridCellCopyIntent(),
-        LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyV):
-            const GridCellPasteIntent(),
-      },
+      shortcuts: shortcuts,
       child: Actions(
-        actions: {
-          GridCellEnterIdent: GridCellEnterAction(child: child),
-          GridCellCopyIntent: GridCellCopyAction(child: child),
-          GridCellPasteIntent: GridCellPasteAction(child: child),
-        },
+        actions: actions,
         child: child,
       ),
     );
   }
+
+  Map<ShortcutActivator, Intent> get shortcuts => {
+        if (shouldAddKeyboardKey(CellKeyboardKey.onEnter))
+          LogicalKeySet(LogicalKeyboardKey.enter): const GridCellEnterIdent(),
+        if (shouldAddKeyboardKey(CellKeyboardKey.onCopy))
+          LogicalKeySet(
+            Platform.isMacOS
+                ? LogicalKeyboardKey.meta
+                : LogicalKeyboardKey.control,
+            LogicalKeyboardKey.keyC,
+          ): const GridCellCopyIntent(),
+      };
+
+  Map<Type, Action<Intent>> get actions => {
+        if (shouldAddKeyboardKey(CellKeyboardKey.onEnter))
+          GridCellEnterIdent: GridCellEnterAction(child: child),
+        if (shouldAddKeyboardKey(CellKeyboardKey.onCopy))
+          GridCellCopyIntent: GridCellCopyAction(child: child),
+      };
+
+  bool shouldAddKeyboardKey(CellKeyboardKey key) =>
+      child.shortcutHandlers.containsKey(key);
 }
 
 class GridCellEnterIdent extends Intent {

+ 2 - 13
frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cell_builder.dart

@@ -1,6 +1,5 @@
 import 'package:appflowy/plugins/database_view/application/cell/cell_controller_builder.dart';
 import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pb.dart';
-import 'package:flutter/services.dart';
 import 'package:flutter/widgets.dart';
 import 'package:flutter/material.dart';
 import '../../application/cell/cell_service.dart';
@@ -152,17 +151,9 @@ abstract class GridCellWidget extends StatefulWidget
 abstract class GridCellState<T extends GridCellWidget> extends State<T> {
   @override
   void initState() {
-    widget.requestFocus.setListener(requestBeginFocus);
-    widget.shortcutHandlers[CellKeyboardKey.onCopy] = () => onCopy();
-    widget.shortcutHandlers[CellKeyboardKey.onInsert] = () {
-      Clipboard.getData("text/plain").then((data) {
-        final s = data?.text;
-        if (s is String) {
-          onInsert(s);
-        }
-      });
-    };
     super.initState();
+
+    widget.requestFocus.setListener(requestBeginFocus);
   }
 
   @override
@@ -183,8 +174,6 @@ abstract class GridCellState<T extends GridCellWidget> extends State<T> {
   void requestBeginFocus();
 
   String? onCopy() => null;
-
-  void onInsert(String value) {}
 }
 
 abstract class GridEditableTextCell<T extends GridCellWidget>

+ 0 - 5
frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/number_cell/number_cell.dart

@@ -88,9 +88,4 @@ class _NumberCellState extends GridEditableTextCell<GridNumberCell> {
   String? onCopy() {
     return _cellBloc.state.cellContent;
   }
-
-  @override
-  void onInsert(String value) {
-    _cellBloc.add(NumberCellEvent.updateCell(value));
-  }
 }

+ 0 - 5
frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/text_cell/text_cell.dart

@@ -125,11 +125,6 @@ class _GridTextCellState extends GridEditableTextCell<GridTextCell> {
   @override
   String? onCopy() => _cellBloc.state.content;
 
-  @override
-  void onInsert(String value) {
-    _cellBloc.add(TextCellEvent.updateText(value));
-  }
-
   @override
   Future<void> focusChanged() {
     _cellBloc.add(

+ 0 - 3
frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/url_cell/url_cell.dart

@@ -191,9 +191,6 @@ class _GridURLCellState extends GridEditableTextCell<GridURLCell> {
 
   @override
   String? onCopy() => _cellBloc.state.content;
-
-  @override
-  void onInsert(String value) => _cellBloc.add(URLCellEvent.updateURL(value));
 }
 
 class _EditURLAccessory extends StatefulWidget {