diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/checklist_cell_editor.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/checklist_cell_editor.dart index e86a2c47c7..4d18862223 100644 --- a/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/checklist_cell_editor.dart +++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/cell_editor/checklist_cell_editor.dart @@ -138,6 +138,10 @@ class _EndEditingTaskIntent extends Intent { const _EndEditingTaskIntent(); } +class _UpdateTaskDescriptionIntent extends Intent { + const _UpdateTaskDescriptionIntent(); +} + /// Represents an existing task @visibleForTesting class ChecklistItem extends StatefulWidget { @@ -175,7 +179,7 @@ class _ChecklistItemState extends State { control: !Platform.isMacOS, ): const _SelectTaskIntent(), const SingleActivator(LogicalKeyboardKey.enter): - const _EndEditingTaskIntent(), + const _UpdateTaskDescriptionIntent(), const SingleActivator(LogicalKeyboardKey.escape): const _EndEditingTaskIntent(), }; @@ -282,6 +286,14 @@ class _ChecklistItemState extends State { return; }, ), + _UpdateTaskDescriptionIntent: + CallbackAction<_UpdateTaskDescriptionIntent>( + onInvoke: (_UpdateTaskDescriptionIntent intent) { + textFieldFocusNode.unfocus(); + widget.onSubmitted?.call(); + return; + }, + ), _EndEditingTaskIntent: CallbackAction<_EndEditingTaskIntent>( onInvoke: (_EndEditingTaskIntent intent) { textFieldFocusNode.unfocus(); @@ -315,6 +327,7 @@ class NewTaskItem extends StatefulWidget { class _NewTaskItemState extends State { final _textEditingController = TextEditingController(); + bool _isCreateButtonEnabled = false; @override void initState() { @@ -339,45 +352,46 @@ class _NewTaskItemState extends State { children: [ const HSpace(8), Expanded( - child: TextField( - focusNode: widget.focusNode, - controller: _textEditingController, - style: Theme.of(context).textTheme.bodyMedium, - decoration: InputDecoration( - border: InputBorder.none, - isCollapsed: true, - contentPadding: const EdgeInsets.symmetric( - vertical: 6.0, - horizontal: 2.0, - ), - hintText: LocaleKeys.grid_checklist_addNew.tr(), - ), - onSubmitted: (taskDescription) { - if (taskDescription.isNotEmpty) { - context - .read() - .add(ChecklistCellEvent.createNewTask(taskDescription)); - _textEditingController.clear(); - } - widget.focusNode.requestFocus(); + child: CallbackShortcuts( + bindings: { + const SingleActivator(LogicalKeyboardKey.enter): () => + _createNewTask(context), }, - onChanged: (value) => setState(() {}), + child: TextField( + focusNode: widget.focusNode, + controller: _textEditingController, + style: Theme.of(context).textTheme.bodyMedium, + maxLines: null, + decoration: InputDecoration( + border: InputBorder.none, + isCollapsed: true, + contentPadding: const EdgeInsets.symmetric( + vertical: 6.0, + horizontal: 2.0, + ), + hintText: LocaleKeys.grid_checklist_addNew.tr(), + ), + onSubmitted: (_) => _createNewTask(context), + onChanged: (value) => setState( + () => _isCreateButtonEnabled = + _textEditingController.text.isNotEmpty, + ), + ), ), ), FlowyTextButton( LocaleKeys.grid_checklist_submitNewTask.tr(), fontSize: 11, - fillColor: _textEditingController.text.isEmpty - ? Theme.of(context).disabledColor - : Theme.of(context).colorScheme.primary, - hoverColor: _textEditingController.text.isEmpty - ? Theme.of(context).disabledColor - : Theme.of(context).colorScheme.primaryContainer, + fillColor: _isCreateButtonEnabled + ? Theme.of(context).colorScheme.primary + : Theme.of(context).disabledColor, + hoverColor: _isCreateButtonEnabled + ? Theme.of(context).colorScheme.primaryContainer + : Theme.of(context).disabledColor, fontColor: Theme.of(context).colorScheme.onPrimary, padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2), - onPressed: _textEditingController.text.isEmpty - ? null - : () { + onPressed: _isCreateButtonEnabled + ? () { context.read().add( ChecklistCellEvent.createNewTask( _textEditingController.text, @@ -385,10 +399,22 @@ class _NewTaskItemState extends State { ); widget.focusNode.requestFocus(); _textEditingController.clear(); - }, + } + : null, ), ], ), ); } + + void _createNewTask(BuildContext context) { + final taskDescription = _textEditingController.text; + if (taskDescription.isNotEmpty) { + context + .read() + .add(ChecklistCellEvent.createNewTask(taskDescription)); + _textEditingController.clear(); + } + widget.focusNode.requestFocus(); + } } diff --git a/frontend/appflowy_flutter/macos/Podfile.lock b/frontend/appflowy_flutter/macos/Podfile.lock index 0fc6b09590..615bfca955 100644 --- a/frontend/appflowy_flutter/macos/Podfile.lock +++ b/frontend/appflowy_flutter/macos/Podfile.lock @@ -142,7 +142,7 @@ SPEC CHECKSUMS: HotKey: e96d8a2ddbf4591131e2bb3f54e69554d90cdca6 hotkey_manager: c32bf0bfe8f934b7bc17ab4ad5c4c142960b023c irondash_engine_context: da62996ee25616d2f01bbeb85dc115d813359478 - local_notifier: c6c371695f914641ab7bc8601944f7e358632d0b + local_notifier: e9506bc66fc70311e8bc7291fb70f743c081e4ff package_info_plus: fa739dd842b393193c5ca93c26798dff6e3d0e0c path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c ReachabilitySwift: 7f151ff156cea1481a8411701195ac6a984f4979