mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-01 19:18:28 -04:00
widgets: fix hidden widgets disrupting index when arranging widgets
fixes #2844 port 1.5
This commit is contained in:
@@ -557,20 +557,19 @@ Item {
|
|||||||
return sectionId === "left" ? leftSection : sectionId === "center" ? centerSection : sectionId === "right" ? rightSection : null;
|
return sectionId === "left" ? leftSection : sectionId === "center" ? centerSection : sectionId === "right" ? rightSection : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Id-based reorder; rebuilds from authoritative objects so every prop (incl. hideWhenIdle) survives
|
// Id-based reorder; rebuilds from authoritative objects so every prop (incl. hideWhenIdle) survives.
|
||||||
|
// Consumes one entry per occurrence so duplicate ids (e.g. two spacers) don't collapse, and
|
||||||
|
// appends unconsumed entries so nothing is silently dropped from the config array.
|
||||||
function reorderSection(sectionId, orderedIds) {
|
function reorderSection(sectionId, orderedIds) {
|
||||||
var current = getWidgetsForSection(sectionId);
|
var remaining = getWidgetsForSection(sectionId).slice();
|
||||||
var byId = {};
|
|
||||||
current.forEach(w => {
|
|
||||||
var id = (typeof w === "string" ? w : w.id);
|
|
||||||
byId[id] = w;
|
|
||||||
});
|
|
||||||
var reordered = [];
|
var reordered = [];
|
||||||
orderedIds.forEach(id => {
|
orderedIds.forEach(id => {
|
||||||
if (byId[id] !== undefined)
|
var idx = remaining.findIndex(w => (typeof w === "string" ? w : w.id) === id);
|
||||||
reordered.push(byId[id]);
|
if (idx < 0)
|
||||||
|
return;
|
||||||
|
reordered.push(remaining.splice(idx, 1)[0]);
|
||||||
});
|
});
|
||||||
setWidgetsForSection(sectionId, reordered);
|
setWidgetsForSection(sectionId, reordered.concat(remaining));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move a widget across sections (or within); committed as one atomic bar-config save
|
// Move a widget across sections (or within); committed as one atomic bar-config save
|
||||||
@@ -979,8 +978,16 @@ Item {
|
|||||||
var isString = typeof widget === "string";
|
var isString = typeof widget === "string";
|
||||||
var widgetId = isString ? widget : widget.id;
|
var widgetId = isString ? widget : widget.id;
|
||||||
var widgetDef = baseWidgetDefinitions.find(w => w.id === widgetId);
|
var widgetDef = baseWidgetDefinitions.find(w => w.id === widgetId);
|
||||||
if (!widgetDef)
|
if (!widgetDef) {
|
||||||
return;
|
// Skipping entries would desync row indices from the config array (issue #2844)
|
||||||
|
widgetDef = {
|
||||||
|
"id": widgetId,
|
||||||
|
"text": widgetId || I18n.tr("Unknown"),
|
||||||
|
"description": "",
|
||||||
|
"icon": "extension",
|
||||||
|
"warning": I18n.tr("Unavailable")
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var item = Object.assign({}, widgetDef);
|
var item = Object.assign({}, widgetDef);
|
||||||
item.enabled = isString ? true : widget.enabled;
|
item.enabled = isString ? true : widget.enabled;
|
||||||
|
|||||||
Reference in New Issue
Block a user