Fix #5492: sort :back by newest members

This commit is contained in:
Oliver Blanthorn 2026-07-31 21:46:25 +02:00
parent 20f60a2119
commit 1f4c5a2c33
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3

View file

@ -68,7 +68,7 @@ export class TabHistoryCompletionSource extends Completions.CompletionSourceFuse
href: node["href"],
parent: node["parent"],
id: node["id"],
level: node["level"] === 0 ? node["level"] : node["level"] - 1,
level: node["level"],
time: node["time"],
})
for (const child of node["children"]) {
@ -77,6 +77,17 @@ export class TabHistoryCompletionSource extends Completions.CompletionSourceFuse
return flat
}
private sortPathsOldestFirst(tree) {
for (const node of tree) {
this.sortPathsOldestFirst(node["children"])
node["latestTime"] = Math.max(
node["time"],
...node["children"].map(child => child["latestTime"]),
)
}
tree.sort((a, b) => a["latestTime"] - b["latestTime"])
}
private addFormatTimeSpan(tree) {
const now = Date.now()
for (const node of tree) {
@ -111,6 +122,7 @@ export class TabHistoryCompletionSource extends Completions.CompletionSourceFuse
if (!history) history = { list: [] }
const tree = this.makeTree(history["list"])
if (tree.length > 0) {
this.sortPathsOldestFirst(tree[0]["children"])
history["list"] = this.flattenTree(tree[0]).reverse()
}
this.addFormatTimeSpan(history["list"])