diff --git a/frontend/appflowy_flutter/.gitignore b/frontend/appflowy_flutter/.gitignore index bbf63caa3e..c1b771a89c 100644 --- a/frontend/appflowy_flutter/.gitignore +++ b/frontend/appflowy_flutter/.gitignore @@ -76,4 +76,4 @@ coverage/ **/failures/*.png -assets/translations/*.json +assets/translations/ diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/accessory/cell_shortcuts.dart b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/accessory/cell_shortcuts.dart index f44a4b5663..f6fcbb977d 100644 --- a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/accessory/cell_shortcuts.dart +++ b/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 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> 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 { diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cell_builder.dart b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cell_builder.dart index 0b9de32497..5ff5755d91 100755 --- a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cell_builder.dart +++ b/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 extends State { @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 extends State { void requestBeginFocus(); String? onCopy() => null; - - void onInsert(String value) {} } abstract class GridEditableTextCell diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/number_cell/number_cell.dart b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/number_cell/number_cell.dart index 1ebd58f2ab..390a52c16a 100644 --- a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/number_cell/number_cell.dart +++ b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/number_cell/number_cell.dart @@ -88,9 +88,4 @@ class _NumberCellState extends GridEditableTextCell { String? onCopy() { return _cellBloc.state.cellContent; } - - @override - void onInsert(String value) { - _cellBloc.add(NumberCellEvent.updateCell(value)); - } } diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/text_cell/text_cell.dart b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/text_cell/text_cell.dart index 7bb18b1377..b74e23712c 100644 --- a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/text_cell/text_cell.dart +++ b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/text_cell/text_cell.dart @@ -125,11 +125,6 @@ class _GridTextCellState extends GridEditableTextCell { @override String? onCopy() => _cellBloc.state.content; - @override - void onInsert(String value) { - _cellBloc.add(TextCellEvent.updateText(value)); - } - @override Future focusChanged() { _cellBloc.add( diff --git a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/url_cell/url_cell.dart b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/url_cell/url_cell.dart index b9497cd591..b9d05523ba 100644 --- a/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/url_cell/url_cell.dart +++ b/frontend/appflowy_flutter/lib/plugins/database_view/widgets/row/cells/url_cell/url_cell.dart @@ -191,9 +191,6 @@ class _GridURLCellState extends GridEditableTextCell { @override String? onCopy() => _cellBloc.state.content; - - @override - void onInsert(String value) => _cellBloc.add(URLCellEvent.updateURL(value)); } class _EditURLAccessory extends StatefulWidget {