Skip to content

Commit 9729e13

Browse files
committed
fix: consume confirm dialog enter key (#7342)
1 parent 5cf3a36 commit 9729e13

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

  • frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space

frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/shared_widget.dart

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -342,23 +342,10 @@ class _ConfirmPopupState extends State<ConfirmPopup> {
342342
@override
343343
Widget build(BuildContext context) {
344344
final theme = AppFlowyTheme.of(context);
345-
return KeyboardListener(
345+
return Focus(
346346
focusNode: focusNode,
347347
autofocus: true,
348-
onKeyEvent: (event) {
349-
if (widget.enableKeyboardListener) {
350-
if (event is KeyDownEvent &&
351-
event.logicalKey == LogicalKeyboardKey.escape) {
352-
Navigator.of(context).pop();
353-
} else if (event is KeyUpEvent &&
354-
event.logicalKey == LogicalKeyboardKey.enter) {
355-
widget.onConfirm(context);
356-
if (widget.closeOnAction) {
357-
Navigator.of(context).pop();
358-
}
359-
}
360-
}
361-
},
348+
onKeyEvent: _handleKeyEvent,
362349
child: Container(
363350
decoration: BoxDecoration(
364351
borderRadius: BorderRadius.circular(theme.borderRadius.xl),
@@ -389,6 +376,30 @@ class _ConfirmPopupState extends State<ConfirmPopup> {
389376
);
390377
}
391378

379+
KeyEventResult _handleKeyEvent(FocusNode node, KeyEvent event) {
380+
if (!widget.enableKeyboardListener) {
381+
return KeyEventResult.ignored;
382+
}
383+
384+
if (event is KeyDownEvent &&
385+
event.logicalKey == LogicalKeyboardKey.escape) {
386+
Navigator.of(context).pop();
387+
return KeyEventResult.handled;
388+
}
389+
390+
if (event is KeyUpEvent &&
391+
event.logicalKey == LogicalKeyboardKey.enter) {
392+
widget.onConfirm(context);
393+
if (widget.closeOnAction) {
394+
Navigator.of(context).pop();
395+
}
396+
// Consume Enter so macOS does not emit its unhandled-key beep.
397+
return KeyEventResult.handled;
398+
}
399+
400+
return KeyEventResult.ignored;
401+
}
402+
392403
Widget _buildTitle() {
393404
final theme = AppFlowyTheme.of(context);
394405
return Row(

0 commit comments

Comments
 (0)