Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: copy cell content

appflowybb22ca5d9313
diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart
index 894eed2ac8..9a1911f003 100755
--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart
+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart
@@ -62,7 +62,7 @@ abstract class GridCellWidget extends StatefulWidget implements CellAccessory, C
final GridCellFocusListener beginFocus = GridCellFocusListener();
@override
- final Map<CellKeyboardKey, CellKeyboardAction> keyboardActionHandlers = {};
+ final Map<CellKeyboardKey, CellKeyboardAction> shortcutHandlers = {};
}
abstract class GridCellState<T extends GridCellWidget> extends State<T> {
@@ -94,7 +94,7 @@ abstract class GridFocusNodeCellState<T extends GridCellWidget> extends GridCell
@override
void initState() {
- widget.keyboardActionHandlers[CellKeyboardKey.onEnter] = () => focusNode.unfocus();
+ widget.shortcutHandlers[CellKeyboardKey.onEnter] = () => focusNode.unfocus();
_listenOnFocusNodeChanged();
super.initState();
}
@@ -109,7 +109,7 @@ abstract class GridFocusNodeCellState<T extends GridCellWidget> extends GridCell
@override
void dispose() {
- widget.keyboardActionHandlers.remove(CellKeyboardKey.onEnter);
+ widget.shortcutHandlers.clear();
focusNode.removeAllListener();
focusNode.dispose();
super.dispose();
diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_shortcuts.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_shortcuts.dart
index 7c122f17ba..2146c939d2 100644
--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_shortcuts.dart
+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_shortcuts.dart
@@ -1,16 +1,18 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
-typedef CellKeyboardAction = VoidCallback;
+typedef CellKeyboardAction = dynamic Function();
enum CellKeyboardKey {
onEnter,
+ onCopy,
+ onInsert,
}
abstract class CellShortcuts extends Widget {
const CellShortcuts({Key? key}) : super(key: key);
- Map<CellKeyboardKey, CellKeyboardAction> get keyboardActionHandlers;
+ Map<CellKeyboardKey, CellKeyboardAction> get shortcutHandlers;
}
class GridCellShortcuts extends StatelessWidget {
@@ -20,9 +22,17 @@ class GridCellShortcuts extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Shortcuts(
- shortcuts: {LogicalKeySet(LogicalKeyboardKey.enter): const GridCellEnterIdent()},
+ shortcuts: {
+ LogicalKeySet(LogicalKeyboardKey.enter): const GridCellEnterIdent(),
+ LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyC): const GridCellCopyIntent(),
+ LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyV): const GridCellInsertIntent(),
+ },
child: Actions(
- actions: {GridCellEnterIdent: GridCellEnterAction(child: child)},
+ actions: {
+ GridCellEnterIdent: GridCellEnterAction(child: child),
+ GridCellCopyIntent: GridCellCopyAction(child: child),
+ GridCellInsertIntent: GridCellInsertAction(child: child),
+ },
child: child,
),
);
@@ -39,7 +49,46 @@ class GridCellEnterAction extends Action<GridCellEnterIdent> {
@override
void invoke(covariant GridCellEnterIdent intent) {
- final callback = child.keyboardActionHandlers[CellKeyboardKey.onEnter];
+ final callback = child.shortcutHandlers[CellKeyboardKey.onEnter];
+ if (callback != null) {
+ callback();
+ }
+ }
+}
+
+class GridCellCopyIntent extends Intent {
+ const GridCellCopyIntent();
+}
+
+class GridCellCopyAction extends Action<GridCellCopyIntent> {
+ final CellShortcuts child;
+ GridCellCopyAction({required this.child});
+
+ @override
+ void invoke(covariant GridCellCopyIntent intent) {
+ final callback = child.shortcutHandlers[CellKeyboardKey.onCopy];
+ if (callback == null) {
+ return;
+ }
+
+ final s = callback();
+ if (s is String) {
+ Clipboard.setData(ClipboardData(text: s));
+ }
+ }
+}
+
+class GridCellInsertIntent extends Intent {
+ const GridCellInsertIntent();
+}
+
+class GridCellInsertAction extends Action<GridCellInsertIntent> {
+ final CellShortcuts child;
+ GridCellInsertAction({required this.child});
+
+ @override
+ void invoke(covariant GridCellInsertIntent intent) {
+ final callback = child.shortcutHandlers[CellKeyboardKey.onEnter];
if (callback != null) {
callback();
}
diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart
index 6f22a7d977..21f44bf2ab 100644
--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart
+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart
@@ -5,6 +5,7 @@ import 'package:flowy_infra_ui/style_widget/icon_button.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'cell_builder.dart';
+import 'cell_shortcuts.dart';
class CheckboxCell extends GridCellWidget {
final GridCellContextBuilder cellContextBuilder;
@@ -24,7 +25,13 @@ class _CheckboxCellState extends GridCellState<CheckboxCell> {
void initState() {
final cellContext = widget.cellContextBuilder.build();
_cellBloc = getIt<CheckboxCellBloc>(param1: cellContext)..add(const CheckboxCellEvent.initial());
-
+ widget.shortcutHandlers[CellKeyboardKey.onCopy] = () {
+ if (_cellBloc.state.isSelected) {
+ return "Yes";
+ } else {
+ return "No";
+ }
+ };
super.initState();
}
diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell/date_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell/date_cell.dart
index eed45464bf..ecc297e4c4 100644
--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell/date_cell.dart
+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell/date_cell.dart
@@ -1,3 +1,4 @@
+import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_shortcuts.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -45,6 +46,7 @@ class _DateCellState extends State<DateCell> {
void initState() {
final cellContext = widget.cellContextBuilder.build();
_cellBloc = getIt<DateCellBloc>(param1: cellContext)..add(const DateCellEvent.initial());
+ widget.shortcutHandlers[CellKeyboardKey.onCopy] = () => _cellBloc.state.dateStr;
super.initState();
}
diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart
index 88aaf5cb3b..3983a7d3c3 100644
--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart
+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'cell_builder.dart';
+import 'cell_shortcuts.dart';
class NumberCell extends GridCellWidget {
final GridCellContextBuilder cellContextBuilder;
@@ -29,6 +30,9 @@ class _NumberCellState extends GridFocusNodeCellState<NumberCell> {
final cellContext = widget.cellContextBuilder.build();
_cellBloc = getIt<NumberCellBloc>(param1: cellContext)..add(const NumberCellEvent.initial());
_controller = TextEditingController(text: contentFromState(_cellBloc.state));
+ widget.shortcutHandlers[CellKeyboardKey.onCopy] = () {
+ return _cellBloc.state.content.fold((content) => content, (r) => null);
+ };
super.initState();
}
diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart
index 6a9fcde98f..48b5628bbd 100644
--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart
+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart
@@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:app_flowy/startup/startup.dart';
import 'package:app_flowy/workspace/application/grid/prelude.dart';
import 'cell_builder.dart';
+import 'cell_shortcuts.dart';
class GridTextCellStyle extends GridCellStyle {
String? placeholder;
@@ -44,6 +45,7 @@ class _GridTextCellState extends GridFocusNodeCellState<GridTextCell> {
_cellBloc.add(const TextCellEvent.initial());
_controller = TextEditingController(text: _cellBloc.state.content);
+ widget.shortcutHandlers[CellKeyboardKey.onCopy] = () => _cellBloc.state.content;
super.initState();
}
diff --git a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/url_cell.dart b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/url_cell.dart
index 5caa014df0..4b4e671901 100644
--- a/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/url_cell.dart
+++ b/frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/url_cell.dart
@@ -3,6 +3,7 @@ import 'package:app_flowy/generated/locale_keys.g.dart';
import 'package:app_flowy/workspace/application/grid/cell/url_cell_bloc.dart';
import 'package:app_flowy/workspace/presentation/home/toast.dart';
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_accessory.dart';
+import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_shortcuts.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/image.dart';
import 'package:flowy_infra/theme.dart';
@@ -86,6 +87,8 @@ class _GridURLCellState extends GridCellState<GridURLCell> {
final cellContext = widget.cellContextBuilder.build() as GridURLCellContext;
_cellBloc = URLCellBloc(cellContext: cellContext);
_cellBloc.add(const URLCellEvent.initial());
+
+ widget.shortcutHandlers[CellKeyboardKey.onCopy] = () => _cellBloc.state.content;
super.initState();
}