Skip to content

Commit 5173d75

Browse files
committed
fix: Make Caching#orderFolder behave like BrowserTree#orderFolder
to avoid haywire when using Caching in CachingTreeWrapper as source for sync cache (unsyncable bookmarks would cause havoc) fixes #2056 Signed-off-by: Marcel Klehr <[email protected]>
1 parent 485fb74 commit 5173d75

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lib/adapters/Caching.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,21 @@ export default class CachingAdapter implements Adapter, BulkImportResource<TItem
165165
throw new UnknownFolderItemOrderError(id + ':' + JSON.stringify(item))
166166
}
167167
})
168-
const newChildren = []
168+
let newChildren = []
169169
order.forEach(item => {
170170
const child = folder.findItem(item.type, item.id)
171171
newChildren.push(child)
172172
})
173-
const diff = difference(folder.children.map(i => i.id), order.map(i => i.id))
173+
const diff = difference(folder.children.map(i => i.type + ':' + i.id), order.map(i => i.type + ':' + i.id))
174174
if (diff.length) {
175175
Logger.log('Folder ordering is missing some of the folders children (moving on): ' + id + ':' + JSON.stringify(diff))
176176
// We don't just append at the end but put them back where they were
177177
// In order to be in line with BrowserTree
178178
diff.forEach(item => {
179-
const child = folder.findItem(item.type, item.id)
179+
const [type, id] = item.split(':')
180+
const child = folder.findItem(type, id)
180181
const index = folder.children.indexOf(child)
181-
newChildren.slice(0, index - 1).concat([child],newChildren.slice(index - 1))
182+
newChildren = newChildren.slice(0, index - 1).concat([child], newChildren.slice(index - 1))
182183
})
183184
}
184185
folder.children = newChildren

0 commit comments

Comments
 (0)