Skip to content

Commit a9a7523

Browse files
committed
chore: insert cell content
1 parent bb22ca5 commit a9a7523

File tree

9 files changed

+76
-27
lines changed

9 files changed

+76
-27
lines changed

frontend/app_flowy/lib/workspace/application/grid/cell/url_cell_bloc.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class URLCellBloc extends Bloc<URLCellEvent, URLCellState> {
2424
url: cellData?.url ?? "",
2525
));
2626
},
27+
updateURL: (String url) {
28+
cellContext.saveCellData(url, deduplicate: true);
29+
},
2730
);
2831
},
2932
);
@@ -53,6 +56,7 @@ class URLCellBloc extends Bloc<URLCellEvent, URLCellState> {
5356
@freezed
5457
class URLCellEvent with _$URLCellEvent {
5558
const factory URLCellEvent.initial() = _InitialCell;
59+
const factory URLCellEvent.updateURL(String url) = _UpdateURL;
5660
const factory URLCellEvent.didReceiveCellUpdate(URLCellData? cell) = _DidReceiveCellUpdate;
5761
}
5862

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_builder.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:app_flowy/workspace/application/grid/cell/cell_service/cell_service.dart';
22
import 'package:flowy_sdk/protobuf/flowy-grid-data-model/grid.pb.dart' show FieldType;
3+
import 'package:flutter/services.dart';
34
import 'package:flutter/widgets.dart';
45
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/row/grid_row.dart';
56
import 'package:flowy_infra/theme.dart';
@@ -69,6 +70,15 @@ abstract class GridCellState<T extends GridCellWidget> extends State<T> {
6970
@override
7071
void initState() {
7172
widget.beginFocus.setListener(() => requestBeginFocus());
73+
widget.shortcutHandlers[CellKeyboardKey.onCopy] = () => onCopy();
74+
widget.shortcutHandlers[CellKeyboardKey.onInsert] = () {
75+
Clipboard.getData("text/plain").then((data) {
76+
final s = data?.text;
77+
if (s is String) {
78+
onInsert(s);
79+
}
80+
});
81+
};
7282
super.initState();
7383
}
7484

@@ -87,6 +97,10 @@ abstract class GridCellState<T extends GridCellWidget> extends State<T> {
8797
}
8898

8999
void requestBeginFocus();
100+
101+
String? onCopy() => null;
102+
103+
void onInsert(String value) {}
90104
}
91105

92106
abstract class GridFocusNodeCellState<T extends GridCellWidget> extends GridCellState<T> {

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/cell_shortcuts.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class GridCellInsertAction extends Action<GridCellInsertIntent> {
8888

8989
@override
9090
void invoke(covariant GridCellInsertIntent intent) {
91-
final callback = child.shortcutHandlers[CellKeyboardKey.onEnter];
91+
final callback = child.shortcutHandlers[CellKeyboardKey.onInsert];
9292
if (callback != null) {
9393
callback();
9494
}

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/checkbox_cell.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:flowy_infra_ui/style_widget/icon_button.dart';
55
import 'package:flutter/widgets.dart';
66
import 'package:flutter_bloc/flutter_bloc.dart';
77
import 'cell_builder.dart';
8-
import 'cell_shortcuts.dart';
98

109
class CheckboxCell extends GridCellWidget {
1110
final GridCellContextBuilder cellContextBuilder;
@@ -25,13 +24,6 @@ class _CheckboxCellState extends GridCellState<CheckboxCell> {
2524
void initState() {
2625
final cellContext = widget.cellContextBuilder.build();
2726
_cellBloc = getIt<CheckboxCellBloc>(param1: cellContext)..add(const CheckboxCellEvent.initial());
28-
widget.shortcutHandlers[CellKeyboardKey.onCopy] = () {
29-
if (_cellBloc.state.isSelected) {
30-
return "Yes";
31-
} else {
32-
return "No";
33-
}
34-
};
3527
super.initState();
3628
}
3729

@@ -66,4 +58,13 @@ class _CheckboxCellState extends GridCellState<CheckboxCell> {
6658
void requestBeginFocus() {
6759
_cellBloc.add(const CheckboxCellEvent.select());
6860
}
61+
62+
@override
63+
String? onCopy() {
64+
if (_cellBloc.state.isSelected) {
65+
return "Yes";
66+
} else {
67+
return "No";
68+
}
69+
}
6970
}

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/date_cell/date_cell.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_shortcuts.dart';
21
import 'package:flowy_infra_ui/style_widget/text.dart';
32
import 'package:flutter/widgets.dart';
43
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -36,17 +35,16 @@ class DateCell extends GridCellWidget {
3635
}
3736

3837
@override
39-
State<DateCell> createState() => _DateCellState();
38+
GridCellState<DateCell> createState() => _DateCellState();
4039
}
4140

42-
class _DateCellState extends State<DateCell> {
41+
class _DateCellState extends GridCellState<DateCell> {
4342
late DateCellBloc _cellBloc;
4443

4544
@override
4645
void initState() {
4746
final cellContext = widget.cellContextBuilder.build();
4847
_cellBloc = getIt<DateCellBloc>(param1: cellContext)..add(const DateCellEvent.initial());
49-
widget.shortcutHandlers[CellKeyboardKey.onCopy] = () => _cellBloc.state.dateStr;
5048
super.initState();
5149
}
5250

@@ -91,4 +89,10 @@ class _DateCellState extends State<DateCell> {
9189
_cellBloc.close();
9290
super.dispose();
9391
}
92+
93+
@override
94+
void requestBeginFocus() {}
95+
96+
@override
97+
String? onCopy() => _cellBloc.state.dateStr;
9498
}

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/number_cell.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import 'dart:async';
2-
32
import 'package:app_flowy/startup/startup.dart';
43
import 'package:app_flowy/workspace/application/grid/prelude.dart';
54
import 'package:flutter/material.dart';
65
import 'package:flutter_bloc/flutter_bloc.dart';
76

87
import 'cell_builder.dart';
9-
import 'cell_shortcuts.dart';
108

119
class NumberCell extends GridCellWidget {
1210
final GridCellContextBuilder cellContextBuilder;
@@ -30,9 +28,6 @@ class _NumberCellState extends GridFocusNodeCellState<NumberCell> {
3028
final cellContext = widget.cellContextBuilder.build();
3129
_cellBloc = getIt<NumberCellBloc>(param1: cellContext)..add(const NumberCellEvent.initial());
3230
_controller = TextEditingController(text: contentFromState(_cellBloc.state));
33-
widget.shortcutHandlers[CellKeyboardKey.onCopy] = () {
34-
return _cellBloc.state.content.fold((content) => content, (r) => null);
35-
};
3631
super.initState();
3732
}
3833

@@ -85,4 +80,14 @@ class _NumberCellState extends GridFocusNodeCellState<NumberCell> {
8580
String contentFromState(NumberCellState state) {
8681
return state.content.fold((l) => l, (r) => "");
8782
}
83+
84+
@override
85+
String? onCopy() {
86+
return _cellBloc.state.content.fold((content) => content, (r) => null);
87+
}
88+
89+
@override
90+
void onInsert(String value) {
91+
_cellBloc.add(NumberCellEvent.updateCell(value));
92+
}
8893
}

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/text_cell.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
44
import 'package:app_flowy/startup/startup.dart';
55
import 'package:app_flowy/workspace/application/grid/prelude.dart';
66
import 'cell_builder.dart';
7-
import 'cell_shortcuts.dart';
87

98
class GridTextCellStyle extends GridCellStyle {
109
String? placeholder;
@@ -44,8 +43,6 @@ class _GridTextCellState extends GridFocusNodeCellState<GridTextCell> {
4443
_cellBloc = getIt<TextCellBloc>(param1: cellContext);
4544
_cellBloc.add(const TextCellEvent.initial());
4645
_controller = TextEditingController(text: _cellBloc.state.content);
47-
48-
widget.shortcutHandlers[CellKeyboardKey.onCopy] = () => _cellBloc.state.content;
4946
super.initState();
5047
}
5148

@@ -95,4 +92,12 @@ class _GridTextCellState extends GridFocusNodeCellState<GridTextCell> {
9592
});
9693
}
9794
}
95+
96+
@override
97+
String? onCopy() => _cellBloc.state.content;
98+
99+
@override
100+
void onInsert(String value) {
101+
_cellBloc.add(TextCellEvent.updateText(value));
102+
}
98103
}

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/cell_editor.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ import 'package:flutter_bloc/flutter_bloc.dart';
88

99
class URLCellEditor extends StatefulWidget with FlowyOverlayDelegate {
1010
final GridURLCellContext cellContext;
11-
const URLCellEditor({required this.cellContext, Key? key}) : super(key: key);
11+
final VoidCallback completed;
12+
const URLCellEditor({required this.cellContext, required this.completed, Key? key}) : super(key: key);
1213

1314
@override
1415
State<URLCellEditor> createState() => _URLCellEditorState();
1516

1617
static void show(
1718
BuildContext context,
1819
GridURLCellContext cellContext,
20+
VoidCallback completed,
1921
) {
2022
FlowyOverlay.of(context).remove(identifier());
2123
final editor = URLCellEditor(
2224
cellContext: cellContext,
25+
completed: completed,
2326
);
2427

2528
//
@@ -46,6 +49,11 @@ class URLCellEditor extends StatefulWidget with FlowyOverlayDelegate {
4649
bool asBarrier() {
4750
return true;
4851
}
52+
53+
@override
54+
void didRemove() {
55+
completed();
56+
}
4957
}
5058

5159
class _URLCellEditorState extends State<URLCellEditor> {

frontend/app_flowy/lib/workspace/presentation/plugins/grid/src/widgets/cell/url_cell/url_cell.dart

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'package:app_flowy/generated/locale_keys.g.dart';
33
import 'package:app_flowy/workspace/application/grid/cell/url_cell_bloc.dart';
44
import 'package:app_flowy/workspace/presentation/home/toast.dart';
55
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_accessory.dart';
6-
import 'package:app_flowy/workspace/presentation/plugins/grid/src/widgets/cell/cell_shortcuts.dart';
76
import 'package:easy_localization/easy_localization.dart';
87
import 'package:flowy_infra/image.dart';
98
import 'package:flowy_infra/theme.dart';
@@ -87,8 +86,6 @@ class _GridURLCellState extends GridCellState<GridURLCell> {
8786
final cellContext = widget.cellContextBuilder.build() as GridURLCellContext;
8887
_cellBloc = URLCellBloc(cellContext: cellContext);
8988
_cellBloc.add(const URLCellEvent.initial());
90-
91-
widget.shortcutHandlers[CellKeyboardKey.onCopy] = () => _cellBloc.state.content;
9289
super.initState();
9390
}
9491

@@ -134,17 +131,28 @@ class _GridURLCellState extends GridCellState<GridURLCell> {
134131
Future<void> _openUrlOrEdit(String url) async {
135132
final uri = Uri.parse(url);
136133
if (url.isNotEmpty && await canLaunchUrl(uri)) {
134+
widget.isFocus.value = false;
137135
await launchUrl(uri);
138136
} else {
139137
final cellContext = widget.cellContextBuilder.build() as GridURLCellContext;
140-
URLCellEditor.show(context, cellContext);
138+
URLCellEditor.show(context, cellContext, () {
139+
widget.isFocus.value = false;
140+
});
141141
}
142142
}
143143

144144
@override
145145
void requestBeginFocus() {
146146
_openUrlOrEdit(_cellBloc.state.url);
147147
}
148+
149+
@override
150+
String? onCopy() => _cellBloc.state.content;
151+
152+
@override
153+
void onInsert(String value) {
154+
_cellBloc.add(URLCellEvent.updateURL(value));
155+
}
148156
}
149157

150158
class _EditURLAccessory extends StatelessWidget with GridCellAccessory {
@@ -164,7 +172,7 @@ class _EditURLAccessory extends StatelessWidget with GridCellAccessory {
164172

165173
@override
166174
void onTap() {
167-
URLCellEditor.show(anchorContext, cellContext);
175+
URLCellEditor.show(anchorContext, cellContext, () {});
168176
}
169177
}
170178

0 commit comments

Comments
 (0)