From 3b457aad1cf981ca6e8b977abea8cb3b5d39da3e Mon Sep 17 00:00:00 2001 From: Factor Date: Thu, 19 Nov 2026 15:58:43 +0100 Subject: [PATCH] fix: dock normalize dedupes ids and trims labels Co-Authored-By: Ovis Fast (Claude) --- herdr/herdr-composer/mods/herdr-composer/dock.js | 6 ++++-- tests/dock.test.mjs | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/herdr/herdr-composer/mods/herdr-composer/dock.js b/herdr/herdr-composer/mods/herdr-composer/dock.js index 8de8b6d..5a63efb 100644 --- a/herdr/herdr-composer/mods/herdr-composer/dock.js +++ b/herdr/herdr-composer/mods/herdr-composer/dock.js @@ -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), }); diff --git a/tests/dock.test.mjs b/tests/dock.test.mjs index dcdff1f..92f0f91 100644 --- a/tests/dock.test.mjs +++ b/tests/dock.test.mjs @@ -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" }, + ]); +});