From 4aa69d0641a1cf80e06f9bdf3fde17a42e0c9c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 7 Dec 2019 16:13:32 +0100 Subject: [PATCH] Do not re-construct tree view if the same records are to display Re-construct the tree looses the cursor, the expand state and the editable cell. Until now, we always re-constructed the tree on display because there was no simple test like the size for the list. Now we compare the flat list of records following the expanded row. We re-construct the table only if they are different. issue8854 review264671003 --- src/view/tree.js | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/view/tree.js b/src/view/tree.js index 113e0116e5..4add4f2752 100644 --- a/src/view/tree.js +++ b/src/view/tree.js @@ -541,25 +541,51 @@ this.selection.hide(); } - var row_records = function() { - return this.rows.map(function(row) { - return row.record; - }); + var group_records = function(group, root) { + var records = []; + for (var i = 0; i < group.length; i++) { + var record = group[i]; + records.push(record); + var path = root.concat([record.id]); + if (Sao.common.contains(expanded, path)) { + var children = record.field_get_client( + this.children_field); + Array.prototype.push.apply( + records, group_records(children, path)); + } + } + return records; + }.bind(this); + + var row_records = function(rows) { + var records = []; + for (var i = 0; i < rows.length; i++) { + var row = rows[i]; + records.push(row.record); + if (row.is_expanded()) { + Array.prototype.push.apply( + records, row_records(row.rows)); + } + } + return records; }.bind(this); var min_display_size = Math.min( this.group.length, this.display_size); - // XXX find better check to keep focus and expanded if (this.children_field) { - this.construct(); + if (!Sao.common.compare( + group_records(this.group.slice(0, min_display_size), []), + row_records(this.rows))) { + this.construct(); + } } else if ((min_display_size > this.rows.length) && Sao.common.compare( this.group.slice(0, this.rows.length), - row_records())) { + row_records(this.rows))) { this.construct(true); } else if ((min_display_size != this.rows.length) || !Sao.common.compare( this.group.slice(0, this.rows.length), - row_records())){ + row_records(this.rows))){ this.construct(); }