From 79a570492e1ff38e9e30f7132ea33003eae3d30a Mon Sep 17 00:00:00 2001 From: Zhigang Zhang Date: Thu, 17 Oct 2024 23:31:23 +0800 Subject: [PATCH] fixup the bug that cousin space doesn't take effect on 1-child-node (#634) --- src/jsmind.layout_provider.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/jsmind.layout_provider.js b/src/jsmind.layout_provider.js index 5296d5fe..6ffd2ea4 100644 --- a/src/jsmind.layout_provider.js +++ b/src/jsmind.layout_provider.js @@ -147,7 +147,8 @@ export class LayoutProvider { this.set_visible(node.children, false); } node_outer_height = Math.max(node._data.view.height, node_outer_height); - if (node.children.length > 1) { + + if (this._should_reserve_cousin_space(node)) { node_outer_height += this.opts.cousin_space; } @@ -196,7 +197,7 @@ export class LayoutProvider { node_outer_height = 0; } node_outer_height = Math.max(node._data.view.height, node_outer_height); - if (node.children.length > 1) { + if (this._should_reserve_cousin_space(node)) { node_outer_height += this.opts.cousin_space; } @@ -216,6 +217,9 @@ export class LayoutProvider { } return total_height; } + _should_reserve_cousin_space(node) { + return node.children.length > 0 && node.parent.children.length > 1; + } get_node_offset(node) { var layout_data = node._data.layout; var offset_cache = null;