From 81c3006c74e789ed2e470b8612529541b358fd26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tizian=20=E3=80=8C=E3=83=86=E3=82=A3=E3=83=84=E3=82=A3?= =?UTF-8?q?=E3=82=A2=E3=83=BC=E3=83=B3=E3=80=8D?= Date: Sun, 11 Oct 2026 19:23:19 +0200 Subject: [PATCH] Fit a read-only table's rows to their cells A table keeps each row's height on its cells, corrected after every layout through a transaction. A read-only editor applies no transaction (EditorState.apply returns while it isn't editable), so a table shown read-only kept the heights it was stored with, or the default of one line: a cell of several lines ran over its row's borders. The table's own height (colsHeight) already took the read-only case in place; the rows' heights now do the same. Upstream's main has the same code. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MMm7usAo6q9ZZRoPkWjoxi --- .../table_block_component/table_node.dart | 8 ++++++++ .../table_block_component/table_view_test.dart | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/src/editor/block_component/table_block_component/table_node.dart b/lib/src/editor/block_component/table_block_component/table_node.dart index 718abaf5..10563916 100644 --- a/lib/src/editor/block_component/table_block_component/table_node.dart +++ b/lib/src/editor/block_component/table_block_component/table_node.dart @@ -209,6 +209,14 @@ class TableNode { _cells[i][row], {TableCellBlockKeys.height: maxHeight}, ); + // A read-only editor applies no transaction, so its rows would + // keep their height whatever their cells hold: they take it in + // place, as the table's height below does. + if (editorState != null && editorState.editable != true) { + _cells[i][row].updateAttributes( + {TableCellBlockKeys.height: maxHeight}, + ); + } } else { _cells[i][row].updateAttributes( {TableCellBlockKeys.height: maxHeight}, diff --git a/test/new/block_component/table_block_component/table_view_test.dart b/test/new/block_component/table_block_component/table_view_test.dart index 9e4815ee..f1a86d9d 100644 --- a/test/new/block_component/table_block_component/table_view_test.dart +++ b/test/new/block_component/table_block_component/table_view_test.dart @@ -83,5 +83,23 @@ void main() async { expect(tableNode.getRowHeight(0), row0beforeHeight); await editor.dispose(); }); + + testWidgets('a read-only table fits its rows to their cells', ( + tester, + ) async { + final tableNode = TableNode.fromList([ + ['one\ntwo\nthree', ''], + ['', ''], + ]); + final editor = tester.editor..addNode(tableNode.node); + + await editor.startTesting(editable: false); + await tester.pumpAndSettle(); + + final cell00 = getCellNode(tableNode.node, 0, 0)!; + expect(tableNode.getRowHeight(0), cell00.children.first.rect.height + 8); + expect(tableNode.getRowHeight(0), greaterThan(tableNode.getRowHeight(1))); + await editor.dispose(); + }); }); }