Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ class AlignOptionAction extends PopoverActionCell {
}

Future<void> onAlignChanged(OptionAlignType align) async {
if (align == this.align) {
return;
}
final selection = editorState.selection;
if (selection == null) {
return;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,7 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>
}

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,
Expand All @@ -368,10 +364,7 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>
child: child,
);
} else {
child = Align(
alignment: alignment,
child: child,
);
child = child;
}

return child;
Expand Down Expand Up @@ -446,16 +439,6 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>
);
}

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand All @@ -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,
);
}

Expand All @@ -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.
Expand Down Expand Up @@ -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<void> clearColumnTextAlign({
/// Clear or adjust the text align of the column at the index where the table cell node is located.
Future<void> clearOrAdjustColumnTextAlign({
required Node tableCellNode,
TableAlign? align,
}) async {
final parentTableNode = tableCellNode.parentTableNode;
if (parentTableNode == null) {
Expand All @@ -400,19 +399,18 @@ 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) {
await apply(transaction);
}
}

/// Clear the text align of the row at the index where the table cell node is located.
Future<void> clearRowTextAlign({
/// Clear or adjust the text align of the row at the index where the table cell node is located.
Future<void> clearOrAdjustRowTextAlign({
required Node tableCellNode,
TableAlign? align,
}) async {
final parentTableNode = tableCellNode.parentTableNode;
if (parentTableNode == null) {
Expand All @@ -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) {
Expand Down
Loading