Skip to content

Commit

Permalink
Update counter-last bugfix from PR Jermolene#7712
Browse files Browse the repository at this point in the history
The bugfix in this PR is now identical to the bugfix from PR Jermolene#7712 so
that we won't get merge conflicts no matter whether that PR or this one
is merged first.
  • Loading branch information
rmunn committed Sep 5, 2023
1 parent 37ffa80 commit a71f6b7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions core/modules/widgets/list.js
Expand Up @@ -250,25 +250,28 @@ ListWidget.prototype.handleListChanges = function(changedTiddlers) {
// If we are providing an counter variable then we must refresh the items, otherwise we can rearrange them
var hasRefreshed = false,t;
if(this.counterName) {
var mustRefreshOldLast = this.children.length < this.list.length;
var oldLastIdx = this.children.length-1;
var mustRefreshOldLast = false;
var oldLength = this.children.length;
// Cycle through the list and remove and re-insert the first item that has changed, and all the remaining items
for(t=0; t<this.list.length; t++) {
if(hasRefreshed || !this.children[t] || this.children[t].parseTreeNode.itemTitle !== this.list[t]) {
if(this.children[t]) {
this.removeListItem(t);
}
this.insertListItem(t,this.list[t]);
if(!hasRefreshed && t === oldLength) {
mustRefreshOldLast = true;
}
hasRefreshed = true;
if(t === oldLastIdx) mustRefreshOldLast = false;
} else {
// Refresh the item we're reusing
var refreshed = this.children[t].refresh(changedTiddlers);
hasRefreshed = hasRefreshed || refreshed;
}
}
// If items were inserted then we must recreate the item that used to be at the last position as it is no longer last
if(mustRefreshOldLast && oldLastIdx >= 0) {
if(mustRefreshOldLast && oldLength > 0) {
var oldLastIdx = oldLength-1;
this.removeListItem(oldLastIdx);
this.insertListItem(oldLastIdx,this.list[oldLastIdx]);
}
Expand Down

0 comments on commit a71f6b7

Please sign in to comment.