fix: dock normalize dedupes ids and trims labels
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
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[]} */
|
/** @type {DockButton[]} */
|
||||||
const out = [];
|
const out = [];
|
||||||
const seen = new Set();
|
const seen = new Set();
|
||||||
|
const ids = new Set();
|
||||||
for (const item of raw) {
|
for (const item of raw) {
|
||||||
if (out.length >= DOCK_LIMIT) break;
|
if (out.length >= DOCK_LIMIT) break;
|
||||||
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
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 text !== "string" || text.trim() === "") continue;
|
||||||
if (typeof mode !== "string" || !MODES.has(mode)) continue;
|
if (typeof mode !== "string" || !MODES.has(mode)) continue;
|
||||||
const key = text.trim();
|
const key = text.trim();
|
||||||
if (seen.has(key)) continue;
|
if (seen.has(key) || ids.has(id)) continue;
|
||||||
seen.add(key);
|
seen.add(key);
|
||||||
|
ids.add(id);
|
||||||
out.push({
|
out.push({
|
||||||
id,
|
id,
|
||||||
label: typeof label === "string" && label.trim() !== "" ? label : defaultLabel(text),
|
label: typeof label === "string" && label.trim() !== "" ? label.trim() : defaultLabel(text),
|
||||||
text,
|
text,
|
||||||
mode: /** @type {"send"|"insert"} */ (mode),
|
mode: /** @type {"send"|"insert"} */ (mode),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -119,3 +119,15 @@ test("starMenu", () => {
|
|||||||
assert.notEqual(on[0].disabled, true);
|
assert.notEqual(on[0].disabled, true);
|
||||||
assert.equal(starMenu({ text: "x", pinned: true })[0].label, "Odepnij bieżący tekst z docka");
|
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" },
|
||||||
|
]);
|
||||||
|
});
|
||||||
Reference in new issue
Block a user