fix: dock normalize dedupes ids and trims labels

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 15:58:43 +01:00
1 parent 6b1f946d25
commit 3b457aad1c
2 files changed
+16 -2

No files matched your search

@@ -54,6 +54,7 @@ export function normalize(raw) {
/** @type {DockButton[]} */
const out = [];
const seen = new Set();
const ids = new Set();
for (const item of raw) {
if (out.length >= DOCK_LIMIT) break;
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
@@ -62,11 +63,12 @@ export function normalize(raw) {
if (typeof text !== "string" || text.trim() === "") continue;
if (typeof mode !== "string" || !MODES.has(mode)) continue;
const key = text.trim();
if (seen.has(key)) continue;
if (seen.has(key) || ids.has(id)) continue;
seen.add(key);
ids.add(id);
out.push({
id,
label: typeof label === "string" && label.trim() !== "" ? label : defaultLabel(text),
label: typeof label === "string" && label.trim() !== "" ? label.trim() : defaultLabel(text),
text,
mode: /** @type {"send"|"insert"} */ (mode),
});
+12
View File
@@ -119,3 +119,15 @@ test("starMenu", () => {
assert.notEqual(on[0].disabled, true);
assert.equal(starMenu({ text: "x", pinned: true })[0].label, "Odepnij bieżący tekst z docka");
});
test("normalize: duplicate ids dropped (first wins), labels trimmed", () => {
const out = normalize([
{ id: "1", text: "a", mode: "send", label: " Moje " },
{ id: "1", text: "b", mode: "send", label: "x" },
{ id: "2", text: "c", mode: "send", label: " " },
]);
assert.deepEqual(out, [
{ id: "1", label: "Moje", text: "a", mode: "send" },
{ id: "2", label: "c", text: "c", mode: "send" },
]);
});