Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
fix: pressing enter on a collapsible list toggle adds an additional new line (#6909)
Lucas244d072a65bd
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dartindex 659727fd4c..5adb27e510 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart@@ -160,6 +160,7 @@ void _customBlockOptionActions(? () => customSlashCommand(slashMenuItems,shouldInsertSlash: false,+ deleteKeywordsByDefault: true,style: styleCustomizer.selectionMenuStyleBuilder(),).handler.call(editorState): () {},diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_list.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_list.dartindex 3dfb967445..fcbd7ea6ca 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_list.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_list.dart@@ -34,6 +34,7 @@ class BlockActionList extends StatelessWidget {editorState: editorState,showSlashMenu: showSlashMenu,),+ const HSpace(2.0),BlockOptionButton(blockComponentContext: blockComponentContext,blockComponentState: blockComponentState,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/_shared_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/_shared_widget.dartindex efdf8d45f4..a3a306abf6 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/_shared_widget.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/_shared_widget.dart@@ -108,12 +108,12 @@ class _SimpleTableAddRowHoverButtonStatefinal simpleTableContext = context.read<SimpleTableContext>();return ValueListenableBuilder(- valueListenable: simpleTableContext.isHoveringOnTableBlock,- builder: (context, isHoveringOnTableBlock, child) {+ valueListenable: simpleTableContext.isHoveringOnTableArea,+ builder: (context, isHoveringOnTableArea, child) {return ValueListenableBuilder(valueListenable: simpleTableContext.hoveringTableCell,builder: (context, hoveringTableCell, child) {- bool shouldShow = isHoveringOnTableBlock;+ bool shouldShow = isHoveringOnTableArea;if (hoveringTableCell != null && _enableHoveringLogicV2) {shouldShow =hoveringTableCell.rowIndex + 1 == hoveringTableCell.rowLength;@@ -240,30 +240,30 @@ class _SimpleTableAddColumnHoverButtonState}return ValueListenableBuilder(- valueListenable:- context.read<SimpleTableContext>().isHoveringOnTableBlock,- builder: (context, isHoveringOnTableBlock, _) {+ valueListenable: context.read<SimpleTableContext>().isHoveringOnTableArea,+ builder: (context, isHoveringOnTableArea, _) {return ValueListenableBuilder(valueListenable: context.read<SimpleTableContext>().hoveringTableCell,builder: (context, hoveringTableCell, _) {- bool shouldShow = isHoveringOnTableBlock;+ bool shouldShow = isHoveringOnTableArea;if (hoveringTableCell != null && _enableHoveringLogicV2) {shouldShow = hoveringTableCell.columnIndex + 1 ==hoveringTableCell.columnLength;}- return shouldShow- ? Positioned(- top: SimpleTableConstants.tableTopPadding -- SimpleTableConstants.cellBorderWidth,- bottom: SimpleTableConstants.addColumnButtonBottomPadding,- right: 0,- child: SimpleTableAddColumnButton(- onTap: () {- widget.editorState.addColumnInTable(widget.node);- },- ),- )- : const SizedBox.shrink();+ return Positioned(+ top: SimpleTableConstants.tableTopPadding -+ SimpleTableConstants.cellBorderWidth,+ bottom: SimpleTableConstants.addColumnButtonBottomPadding,+ right: 0,+ child: Opacity(+ opacity: shouldShow ? 1.0 : 0.0,+ child: SimpleTableAddColumnButton(+ onTap: () {+ widget.editorState.addColumnInTable(widget.node);+ },+ ),+ ),+ );},);},@@ -340,13 +340,12 @@ class SimpleTableAddColumnAndRowHoverButton extends StatelessWidget {}return ValueListenableBuilder(- valueListenable:- context.read<SimpleTableContext>().isHoveringOnTableBlock,- builder: (context, isHoveringOnTableBlock, child) {+ valueListenable: context.read<SimpleTableContext>().isHoveringOnTableArea,+ builder: (context, isHoveringOnTableArea, child) {return ValueListenableBuilder(valueListenable: context.read<SimpleTableContext>().hoveringTableCell,builder: (context, hoveringTableCell, child) {- bool shouldShow = isHoveringOnTableBlock;+ bool shouldShow = isHoveringOnTableArea;if (hoveringTableCell != null && _enableHoveringLogicV2) {shouldShow = hoveringTableCell.isLastCellInTable;}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_block_component.dartindex cf64233490..c6efde601b 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_block_component.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_block_component.dart@@ -194,21 +194,7 @@ class _SimpleTableBlockWidgetState extends State<SimpleTableBlockWidget>child: _buildTable(),);- child = Container(- alignment: Alignment.topLeft,- padding: padding,- child: child,- );-- if (widget.showActions && widget.actionBuilder != null) {- child = BlockComponentActionWrapper(- node: node,- actionBuilder: widget.actionBuilder!,- child: child,- );- }-- return Provider.value(+ child = Provider.value(value: simpleTableContext,child: MouseRegion(onEnter: (event) =>@@ -219,54 +205,71 @@ class _SimpleTableBlockWidgetState extends State<SimpleTableBlockWidget>child: child,),);++ if (widget.showActions && widget.actionBuilder != null) {+ child = BlockComponentActionWrapper(+ node: node,+ actionBuilder: widget.actionBuilder!,+ child: child,+ );+ }++ return child;}Widget _buildTable() {// IntrinsicWidth and IntrinsicHeight are used to make the table size fit the content.- return Provider.value(- value: simpleTableContext,- child: Stack(- children: [- MouseRegion(- onEnter: (event) =>- simpleTableContext.isHoveringOnTable.value = true,- onExit: (event) {- simpleTableContext.isHoveringOnTable.value = false;- simpleTableContext.hoveringTableCell.value = null;- },- child: Scrollbar(- controller: scrollController,- child: SingleChildScrollView(+ return MouseRegion(+ onEnter: (event) => simpleTableContext.isHoveringOnTableArea.value = true,+ onExit: (event) {+ simpleTableContext.isHoveringOnTableArea.value = false;+ },+ child: Provider.value(+ value: simpleTableContext,+ child: Stack(+ children: [+ MouseRegion(+ hitTestBehavior: HitTestBehavior.opaque,+ onEnter: (event) =>+ simpleTableContext.isHoveringOnColumnsAndRows.value = true,+ onExit: (event) {+ simpleTableContext.isHoveringOnColumnsAndRows.value = false;+ simpleTableContext.hoveringTableCell.value = null;+ },+ child: Scrollbar(controller: scrollController,- scrollDirection: Axis.horizontal,- child: Padding(- padding: SimpleTableConstants.tablePadding,- child: IntrinsicWidth(- child: IntrinsicHeight(- child: Column(- mainAxisSize: MainAxisSize.min,- crossAxisAlignment: CrossAxisAlignment.start,- children: _buildRows(),+ child: SingleChildScrollView(+ controller: scrollController,+ scrollDirection: Axis.horizontal,+ child: Padding(+ padding: SimpleTableConstants.tablePadding,+ child: IntrinsicWidth(+ child: IntrinsicHeight(+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: _buildRows(),+ ),),),),),),),- ),- SimpleTableAddColumnHoverButton(- editorState: editorState,- node: node,- ),- SimpleTableAddRowHoverButton(- editorState: editorState,- tableNode: node,- ),- SimpleTableAddColumnAndRowHoverButton(- editorState: editorState,- node: node,- ),- ],+ SimpleTableAddColumnHoverButton(+ editorState: editorState,+ node: node,+ ),+ SimpleTableAddRowHoverButton(+ editorState: editorState,+ tableNode: node,+ ),+ SimpleTableAddColumnAndRowHoverButton(+ editorState: editorState,+ node: node,+ ),+ ],+ ),),);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_constants.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_constants.dartindex 63d7e4dfe6..3882d815c3 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_constants.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_constants.dart@@ -4,12 +4,17 @@ import 'package:appflowy_backend/log.dart';import 'package:appflowy_editor/appflowy_editor.dart';import 'package:flutter/material.dart';-const enableTableDebugLog = true;+const enableTableDebugLog = false;class SimpleTableContext {SimpleTableContext() {if (enableTableDebugLog) {- isHoveringOnTable.addListener(_onHoveringOnTableChanged);+ isHoveringOnColumnsAndRows.addListener(+ _onHoveringOnColumnsAndRowsChanged,+ );+ isHoveringOnTableArea.addListener(+ _onHoveringOnTableAreaChanged,+ );hoveringTableCell.addListener(_onHoveringTableNodeChanged);selectingColumn.addListener(_onSelectingColumnChanged);selectingRow.addListener(_onSelectingRowChanged);@@ -18,20 +23,40 @@ class SimpleTableContext {}}- final ValueNotifier<bool> isHoveringOnTable = ValueNotifier(false);+ // the area only contains the columns and rows,+ // the add row button, add column button, and add column and row button are not part of the table area+ final ValueNotifier<bool> isHoveringOnColumnsAndRows = ValueNotifier(false);++ // the table area contains the columns and rows,+ // the add row button, add column button, and add column and row button are not part of the table area,+ // not including the selection area and padding+ final ValueNotifier<bool> isHoveringOnTableArea = ValueNotifier(false);++ // the table block area contains the table area and the add row button, add column button, and add column and row button+ // also, the table block area contains the selection area and padding+ final ValueNotifier<bool> isHoveringOnTableBlock = ValueNotifier(false);++ // the hovering table cell is the cell that the mouse is hovering onfinal ValueNotifier<Node?> hoveringTableCell = ValueNotifier(null);++ // the hovering on resize handle is the resize handle that the mouse is hovering onfinal ValueNotifier<Node?> hoveringOnResizeHandle = ValueNotifier(null);++ // the selecting column is the column that the user is selectingfinal ValueNotifier<int?> selectingColumn = ValueNotifier(null);++ // the selecting row is the row that the user is selectingfinal ValueNotifier<int?> selectingRow = ValueNotifier(null);++ // the is selecting table is the table that the user is selectingfinal ValueNotifier<bool> isSelectingTable = ValueNotifier(false);- final ValueNotifier<bool> isHoveringOnTableBlock = ValueNotifier(false);- void _onHoveringOnTableChanged() {+ void _onHoveringOnColumnsAndRowsChanged() {if (!enableTableDebugLog) {return;}- Log.debug('isHoveringOnTable: ${isHoveringOnTable.value}');+ Log.debug('isHoveringOnTable: ${isHoveringOnColumnsAndRows.value}');}void _onHoveringTableNodeChanged() {@@ -79,14 +104,23 @@ class SimpleTableContext {Log.debug('isHoveringOnTableBlock: ${isHoveringOnTableBlock.value}');}+ void _onHoveringOnTableAreaChanged() {+ if (!enableTableDebugLog) {+ return;+ }++ Log.debug('isHoveringOnTableArea: ${isHoveringOnTableArea.value}');+ }+void dispose() {- isHoveringOnTable.dispose();+ isHoveringOnColumnsAndRows.dispose();+ isHoveringOnTableBlock.dispose();+ isHoveringOnTableArea.dispose();hoveringTableCell.dispose();hoveringOnResizeHandle.dispose();selectingColumn.dispose();selectingRow.dispose();isSelectingTable.dispose();- isHoveringOnTableBlock.dispose();}}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_node_extension.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_node_extension.dartindex 553497a459..d31f127b91 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_node_extension.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_node_extension.dart@@ -16,9 +16,9 @@ enum TableAlign {right;String get name => switch (this) {- TableAlign.left => 'Left',- TableAlign.center => 'Center',- TableAlign.right => 'Right',+ TableAlign.left => 'left',+ TableAlign.center => 'center',+ TableAlign.right => 'right',};FlowySvgData get leftIconSvg => switch (this) {diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dartindex c715330c54..508e2a8349 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dart@@ -125,7 +125,6 @@ CharacterShortcutEvent insertChildNodeInsideToggleList = CharacterShortcutEvent(selection.start.path.next,[toggleListBlockNode(collapsed: true, delta: slicedDelta),- paragraphNode(),],)..afterSelection = Selection.collapsed(diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lockindex c33f4844df..71bc08bf67 100644--- a/frontend/appflowy_flutter/pubspec.lock+++ b/frontend/appflowy_flutter/pubspec.lock@@ -61,8 +61,8 @@ packages:dependency: "direct main"description:path: "."- ref: "817c965"- resolved-ref: "817c965f26804efc09ecf97b1fb9d7d4e139ef4b"+ ref: ac3b090+ resolved-ref: ac3b0906ea2e7f2e7e3c2c7852e9ec3529e07512url: "https://github.com/AppFlowy-IO/appflowy-editor.git"source: gitversion: "4.0.0"diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yamlindex 3794027cb8..29a3d57cf7 100644--- a/frontend/appflowy_flutter/pubspec.yaml+++ b/frontend/appflowy_flutter/pubspec.yaml@@ -173,7 +173,7 @@ dependency_overrides:appflowy_editor:git:url: https://github.com/AppFlowy-IO/appflowy-editor.git- ref: "817c965"+ ref: "ac3b090"appflowy_editor_plugins:git:diff --git a/frontend/appflowy_flutter/test/unit_test/document/shortcuts/toggle_list_shortcut_test.dart b/frontend/appflowy_flutter/test/unit_test/document/shortcuts/toggle_list_shortcut_test.dartindex 048fd7d8e9..fa84293a33 100644--- a/frontend/appflowy_flutter/test/unit_test/document/shortcuts/toggle_list_shortcut_test.dart+++ b/frontend/appflowy_flutter/test/unit_test/document/shortcuts/toggle_list_shortcut_test.dart@@ -84,5 +84,31 @@ void main() {editorState.dispose();});++ testWidgets('press the enter key in empty toggle list', (tester) async {+ const text = 'AppFlowy';++ final document = createDocument([+ toggleListBlockNode(text: text, collapsed: true),+ ]);++ final editorState = EditorState(document: document);+ editorState.selection = Selection.collapsed(+ Position(path: [0], offset: text.length),+ );++ // simulate the enter key press+ final result = await insertChildNodeInsideToggleList.execute(editorState);+ expect(result, true);++ final nodes = editorState.document.root.children;+ expect(nodes.length, 2);+ for (var i = 0; i < nodes.length; i++) {+ final node = nodes[i];+ expect(node.type, ToggleListBlockKeys.type);+ }++ editorState.dispose();+ });});}diff --git a/frontend/scripts/code_generation/language_files/generate_language_files.cmd b/frontend/scripts/code_generation/language_files/generate_language_files.cmdindex 7b14503810..9536e4359c 100644--- a/frontend/scripts/code_generation/language_files/generate_language_files.cmd+++ b/frontend/scripts/code_generation/language_files/generate_language_files.cmd@@ -16,6 +16,8 @@ echo Copying resources/translations to appflowy_flutter/assets/translationsxcopy /E /Y /I ..\resources\translations assets\translationsREM call flutter packages pub get+call flutter pub get+call flutter packages pub getecho Specifying source directory for AppFlowy Localizations.call dart run easy_localization:generate -S assets/translations/