Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcut exit link 2393 #124

Merged
merged 4 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"openLink": "open link",
"copyLink": "copy link",
"removeLink": "remove link",
"urlHint": "url",
"highlightColor": "highlight color",
"clearHighlightColor": "clear highlight color",
"customColor": "custom color",
Expand Down
54 changes: 34 additions & 20 deletions lib/src/editor/toolbar/items/link/link_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:appflowy_editor/src/infra/flowy_svg.dart';
import 'package:appflowy_editor/src/l10n/l10n.dart';
import 'package:flutter/material.dart';
import 'package:appflowy_editor/src/editor/toolbar/items/utils/overlay_util.dart';
import 'package:flutter/services.dart';

class LinkMenu extends StatefulWidget {
const LinkMenu({
Expand All @@ -13,6 +14,7 @@ class LinkMenu extends StatefulWidget {
required this.onOpenLink,
required this.onCopyLink,
required this.onRemoveLink,
required this.onDismiss,
}) : super(key: key);

final String? linkText;
Expand All @@ -21,6 +23,7 @@ class LinkMenu extends StatefulWidget {
final VoidCallback onOpenLink;
final VoidCallback onCopyLink;
final VoidCallback onRemoveLink;
final VoidCallback onDismiss;

@override
State<LinkMenu> createState() => _LinkMenuState();
Expand Down Expand Up @@ -81,27 +84,38 @@ class _LinkMenuState extends State<LinkMenu> {
}

Widget _buildInput() {
return TextField(
focusNode: _focusNode,
textAlign: TextAlign.left,
controller: _textEditingController,
onSubmitted: widget.onSubmitted,
decoration: InputDecoration(
hintText: 'URL',
contentPadding: const EdgeInsets.all(16.0),
isDense: true,
suffixIcon: IconButton(
padding: const EdgeInsets.all(4.0),
icon: const FlowySvg(
name: 'clear',
width: 24,
height: 24,
return RawKeyboardListener(
focusNode: FocusNode(),
onKey: (key) {
if (key is! RawKeyDownEvent) {
return;
}
if (key.logicalKey == LogicalKeyboardKey.escape) {
widget.onDismiss();
}
vincenzoursano marked this conversation as resolved.
Show resolved Hide resolved
},
child: TextField(
focusNode: _focusNode,
textAlign: TextAlign.left,
controller: _textEditingController,
onSubmitted: widget.onSubmitted,
decoration: InputDecoration(
hintText: AppFlowyEditorLocalizations.current.urlHint.toUpperCase(),
contentPadding: const EdgeInsets.all(16.0),
isDense: true,
suffixIcon: IconButton(
padding: const EdgeInsets.all(4.0),
icon: const FlowySvg(
name: 'clear',
width: 24,
height: 24,
),
onPressed: _textEditingController.clear,
splashRadius: 5,
),
border: const OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
),
onPressed: _textEditingController.clear,
splashRadius: 5,
),
border: const OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
),
),
);
Expand Down
1 change: 1 addition & 0 deletions lib/src/editor/toolbar/items/link/link_toolbar_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ void showLinkMenu(
editorState.apply(transaction);
dismissOverlay();
},
onDismiss: dismissOverlay,
);
},
).build();
Expand Down
3 changes: 2 additions & 1 deletion lib/src/l10n/intl/messages_en.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class MessageLookup extends MessageLookupByLibrary {
"tint7": MessageLookupByLibrary.simpleMessage("Tint 7"),
"tint8": MessageLookupByLibrary.simpleMessage("Tint 8"),
"tint9": MessageLookupByLibrary.simpleMessage("Tint 9"),
"underline": MessageLookupByLibrary.simpleMessage("Underline")
"underline": MessageLookupByLibrary.simpleMessage("Underline"),
"urlHint": MessageLookupByLibrary.simpleMessage("url")
};
}
10 changes: 10 additions & 0 deletions lib/src/l10n/l10n.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/src/service/selection_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class _AppFlowySelectionState extends State<AppFlowySelection>
currentSelectedNodes = [];
currentSelection.value = null;

_clearToolbar();
clearCursor();
// clear selection areas
_selectionAreas
Expand Down
33 changes: 33 additions & 0 deletions test/new/toolbar/items/link/link_menu_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:appflowy_editor/src/core/document/text_delta.dart';
import 'package:appflowy_editor/src/editor/toolbar/items/link/link_menu.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../../infra/testable_editor.dart';
Expand All @@ -21,6 +22,7 @@ void main() async {
onSubmitted: (text) {
submittedText = text;
},
onDismiss: () {},
);
await tester.pumpWidget(
MaterialApp(
Expand Down Expand Up @@ -87,5 +89,36 @@ void main() async {

expect(find.text(link, findRichText: true), findsOneWidget);
});

testWidgets('test dismiss link menu by pressing ESC', (tester) async {
var dismissed = false;

final linkMenu = LinkMenu(
onOpenLink: () {},
onCopyLink: () {},
onRemoveLink: () {},
onSubmitted: (text) {},
onDismiss: () {
dismissed = true;
},
);

await tester.pumpWidget(
MaterialApp(
home: Material(
child: linkMenu,
),
),
);

expect(find.byType(TextButton), findsNothing);
expect(find.byType(TextField), findsOneWidget);

// Simulate keyboard press event for the Escape key
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();

expect(dismissed, true);
});
});
}