mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: pasting a link in a URL grid crashes the app
This commit is contained in:
parent
706a5e784f
commit
f6edd4b32b
2
frontend/appflowy_flutter/.gitignore
vendored
2
frontend/appflowy_flutter/.gitignore
vendored
@ -76,4 +76,4 @@ coverage/
|
|||||||
|
|
||||||
**/failures/*.png
|
**/failures/*.png
|
||||||
|
|
||||||
assets/translations/*.json
|
assets/translations/
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
@ -22,23 +24,35 @@ class GridCellShortcuts extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Shortcuts(
|
return Shortcuts(
|
||||||
shortcuts: {
|
shortcuts: shortcuts,
|
||||||
LogicalKeySet(LogicalKeyboardKey.enter): const GridCellEnterIdent(),
|
|
||||||
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyC):
|
|
||||||
const GridCellCopyIntent(),
|
|
||||||
LogicalKeySet(LogicalKeyboardKey.control, LogicalKeyboardKey.keyV):
|
|
||||||
const GridCellPasteIntent(),
|
|
||||||
},
|
|
||||||
child: Actions(
|
child: Actions(
|
||||||
actions: {
|
actions: actions,
|
||||||
GridCellEnterIdent: GridCellEnterAction(child: child),
|
|
||||||
GridCellCopyIntent: GridCellCopyAction(child: child),
|
|
||||||
GridCellPasteIntent: GridCellPasteAction(child: child),
|
|
||||||
},
|
|
||||||
child: child,
|
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 {
|
class GridCellEnterIdent extends Intent {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import 'package:appflowy/plugins/database_view/application/cell/cell_controller_builder.dart';
|
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:appflowy_backend/protobuf/flowy-database2/field_entities.pb.dart';
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../application/cell/cell_service.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> {
|
abstract class GridCellState<T extends GridCellWidget> extends State<T> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
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();
|
super.initState();
|
||||||
|
|
||||||
|
widget.requestFocus.setListener(requestBeginFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -183,8 +174,6 @@ abstract class GridCellState<T extends GridCellWidget> extends State<T> {
|
|||||||
void requestBeginFocus();
|
void requestBeginFocus();
|
||||||
|
|
||||||
String? onCopy() => null;
|
String? onCopy() => null;
|
||||||
|
|
||||||
void onInsert(String value) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class GridEditableTextCell<T extends GridCellWidget>
|
abstract class GridEditableTextCell<T extends GridCellWidget>
|
||||||
|
@ -88,9 +88,4 @@ class _NumberCellState extends GridEditableTextCell<GridNumberCell> {
|
|||||||
String? onCopy() {
|
String? onCopy() {
|
||||||
return _cellBloc.state.cellContent;
|
return _cellBloc.state.cellContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void onInsert(String value) {
|
|
||||||
_cellBloc.add(NumberCellEvent.updateCell(value));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -125,11 +125,6 @@ class _GridTextCellState extends GridEditableTextCell<GridTextCell> {
|
|||||||
@override
|
@override
|
||||||
String? onCopy() => _cellBloc.state.content;
|
String? onCopy() => _cellBloc.state.content;
|
||||||
|
|
||||||
@override
|
|
||||||
void onInsert(String value) {
|
|
||||||
_cellBloc.add(TextCellEvent.updateText(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> focusChanged() {
|
Future<void> focusChanged() {
|
||||||
_cellBloc.add(
|
_cellBloc.add(
|
||||||
|
@ -191,9 +191,6 @@ class _GridURLCellState extends GridEditableTextCell<GridURLCell> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String? onCopy() => _cellBloc.state.content;
|
String? onCopy() => _cellBloc.state.content;
|
||||||
|
|
||||||
@override
|
|
||||||
void onInsert(String value) => _cellBloc.add(URLCellEvent.updateURL(value));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _EditURLAccessory extends StatefulWidget {
|
class _EditURLAccessory extends StatefulWidget {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user