diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/align_option_action.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/align_option_action.dart index efa1c3e15c777..8b142acf3b53c 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/align_option_action.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/option/align_option_action.dart @@ -126,9 +126,6 @@ class AlignOptionAction extends PopoverActionCell { } Future onAlignChanged(OptionAlignType align) async { - if (align == this.align) { - return; - } final selection = editorState.selection; if (selection == null) { return; @@ -137,6 +134,9 @@ class AlignOptionAction extends PopoverActionCell { if (node == null) { return; } + if (align == this.align && node.type != SimpleTableBlockKeys.type) { + return; + } // the align attribute for simple table is not same as the align type, // so we need to convert the align type to the align attribute if (node.type == SimpleTableBlockKeys.type) { diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_cell_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_cell_block_component.dart index 29b3c3455f161..ee5802df1ac95 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_cell_block_component.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_cell_block_component.dart @@ -347,11 +347,7 @@ class SimpleTableCellBlockWidgetState extends State } Widget _buildCellContent(Node childNode) { - final alignment = _buildAlignment(); - - Widget child = IntrinsicWidth( - child: editorState.renderer.build(context, childNode), - ); + Widget child = editorState.renderer.build(context, childNode); final notSupportAlignmentBlocks = [ DividerBlockKeys.type, @@ -368,10 +364,7 @@ class SimpleTableCellBlockWidgetState extends State child: child, ); } else { - child = Align( - alignment: alignment, - child: child, - ); + child = child; } return child; @@ -446,16 +439,6 @@ class SimpleTableCellBlockWidgetState extends State ); } - Alignment _buildAlignment() { - Alignment alignment = Alignment.topLeft; - if (node.columnAlign != TableAlign.left) { - alignment = node.columnAlign.alignment; - } else if (node.rowAlign != TableAlign.left) { - alignment = node.rowAlign.alignment; - } - return alignment; - } - Decoration _buildDecoration() { final backgroundColor = _buildBackgroundColor(); final border = borderBuilder.buildBorder( diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_style_operation.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_style_operation.dart index 7afa7da66b338..db051929dfaf8 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_style_operation.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_style_operation.dart @@ -107,14 +107,9 @@ extension TableOptionOperation on EditorState { required Node tableCellNode, required TableAlign align, }) async { - await clearColumnTextAlign(tableCellNode: tableCellNode); - - final columnIndex = tableCellNode.columnIndex; - await _updateTableAttributes( + await clearOrAdjustColumnTextAlign( tableCellNode: tableCellNode, - attributeKey: SimpleTableBlockKeys.columnAligns, - source: tableCellNode.columnAligns, - duplicatedEntry: MapEntry(columnIndex.toString(), align.key), + align: align, ); } @@ -136,14 +131,9 @@ extension TableOptionOperation on EditorState { required Node tableCellNode, required TableAlign align, }) async { - await clearRowTextAlign(tableCellNode: tableCellNode); - - final rowIndex = tableCellNode.rowIndex; - await _updateTableAttributes( + await clearOrAdjustRowTextAlign( tableCellNode: tableCellNode, - attributeKey: SimpleTableBlockKeys.rowAligns, - source: tableCellNode.rowAligns, - duplicatedEntry: MapEntry(rowIndex.toString(), align.key), + align: align, ); } @@ -162,18 +152,26 @@ extension TableOptionOperation on EditorState { return; } - final transaction = this.transaction; - Attributes attributes = tableNode.attributes; - for (var i = 0; i < tableNode.columnLength; i++) { - attributes = attributes.mergeValues( - SimpleTableBlockKeys.columnAligns, - attributes[SimpleTableBlockKeys.columnAligns] ?? - SimpleTableColumnAlignMap(), - duplicatedEntry: MapEntry(i.toString(), align.key), - ); + final transaction = this.transaction, + columnLength = tableNode.columnLength, + rowLength = tableNode.rowLength; + for (var i = 0; i < columnLength; i++) { + for (var j = 0; j < rowLength; ++j) { + final cell = tableNode.getTableCellNode( + rowIndex: j, + columnIndex: i, + ); + if (cell == null) { + continue; + } + for (final child in cell.children) { + transaction.updateNode(child, {blockComponentAlign: align.key}); + } + } + } + if (transaction.operations.isNotEmpty) { + await apply(transaction); } - transaction.updateNode(tableNode, attributes); - await apply(transaction); } /// Update the background color of the column at the index where the table cell node is located. @@ -380,9 +378,10 @@ extension TableOptionOperation on EditorState { await apply(transaction); } - /// Clear the text align of the column at the index where the table cell node is located. - Future clearColumnTextAlign({ + /// Clear or adjust the text align of the column at the index where the table cell node is located. + Future clearOrAdjustColumnTextAlign({ required Node tableCellNode, + TableAlign? align, }) async { final parentTableNode = tableCellNode.parentTableNode; if (parentTableNode == null) { @@ -400,9 +399,7 @@ extension TableOptionOperation on EditorState { continue; } for (final child in cell.children) { - transaction.updateNode(child, { - blockComponentAlign: null, - }); + transaction.updateNode(child, {blockComponentAlign: align?.key}); } } if (transaction.operations.isNotEmpty) { @@ -410,9 +407,10 @@ extension TableOptionOperation on EditorState { } } - /// Clear the text align of the row at the index where the table cell node is located. - Future clearRowTextAlign({ + /// Clear or adjust the text align of the row at the index where the table cell node is located. + Future clearOrAdjustRowTextAlign({ required Node tableCellNode, + TableAlign? align, }) async { final parentTableNode = tableCellNode.parentTableNode; if (parentTableNode == null) { @@ -430,12 +428,7 @@ extension TableOptionOperation on EditorState { continue; } for (final child in cell.children) { - transaction.updateNode( - child, - { - blockComponentAlign: null, - }, - ); + transaction.updateNode(child, {blockComponentAlign: align?.key}); } } if (transaction.operations.isNotEmpty) {