Elffuss BraidHub

utopia-ia/elffuss-code public

Picking a model repaints its card, not the whole Settings panel

47cf02a made the model card say "loading…" and highlight the new model
when the load ends by calling renderSettings() on click and again after
the load. renderSettings() starts with box.replaceChildren(), so anything
typed meanwhile in Settings and not saved on change (the feedback box, the
bridge token) was wiped, and focus fell to <body>; with Enter on a card it
fell at once and then jumped to the "Settings" heading. Big models take a
long time to load, so this was easy to hit.

The cards are now painted by one function and repainted in place (class,
aria-pressed, aria-busy, text): the same buttons, the same focus.
changeModel() repaints the open panel's cards when any load ends.

The model dot now focuses the ACTIVE card: '.model-card.active,
.model-card' returned the first card in document order.

settings-ux.mjs: text typed in Settings during a load survives with its
focus, Enter on a card keeps focus on it during and after a load, and the
model dot lands on the active card. All four fail on the previous tree.
Changeset32452296a328f9d9abc5f0e5de418afd58b0c943d504e8ddae482b3a3f332ac6
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-10 19:25 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 14:15 +02:00
Parents88b3f553b4fc

Browse the files at this changeset

2 files changed

modified tests/settings-ux.mjs +24 −1
@@ -10,7 +10,9 @@
1010 // 5. El punto del modelo dice con palabras qué modelo y en qué estado, y es
1111 // un botón que lleva a Ajustes.
1212 // 6. Al elegir un modelo, su tarjeta dice «cargando…» y, al terminar, queda
13-// resaltada (antes el resaltado se quedaba en el anterior).
13+// resaltada (antes el resaltado se quedaba en el anterior). Lo escrito en
14+// Ajustes mientras carga no se pierde y el foco no se va a <body>.
15+// 5. El punto del modelo lleva el foco a la tarjeta del modelo activo.
1416 // El modelo es de mentira: page.route sirve un providers/onnx.js propio.
1517 //
1618 // BASE=http://127.0.0.1:8898 node tests/settings-ux.mjs
@@ -72,9 +74,27 @@
7274 await p.waitForTimeout(150);
7375 const durante = await p.evaluate(() => { const c = [...document.querySelectorAll('#settings-panel .model-card')].find(x => /Qwen3.5-0.8B/.test(x.textContent)); return { busy: c?.getAttribute('aria-busy'), txt: c?.textContent }; });
7476 ok('6 · al elegir un modelo, su tarjeta dice «cargando…» (aria-busy)', durante.busy === 'true' && /cargando/.test(durante.txt), JSON.stringify(durante));
77+// …y mientras carga se puede seguir escribiendo en Ajustes: al terminar la carga
78+// el panel ya no se rehace entero (antes se borraba el texto y el foco iba a <body>)
79+await p.locator('#tel-feedback').fill('texto a medio escribir');
7580 await p.waitForTimeout(1500);
7681 const tras = await p.evaluate(() => { const c = [...document.querySelectorAll('#settings-panel .model-card')].find(x => /Qwen3.5-0.8B/.test(x.textContent)); return { activa: c?.classList.contains('active'), pressed: c?.getAttribute('aria-pressed') }; });
7782 ok('6 · al terminar, la tarjeta del modelo cargado queda resaltada', tras.activa && tras.pressed === 'true', JSON.stringify(tras));
83+const escrito = await p.evaluate(() => ({ valor: document.getElementById('tel-feedback')?.value, foco: document.activeElement?.id || document.activeElement?.tagName }));
84+ok('6 · lo escrito en Ajustes mientras cargaba sigue ahí, con el foco', escrito.valor === 'texto a medio escribir' && escrito.foco === 'tel-feedback', JSON.stringify(escrito));
85+// Con el teclado: Enter en una tarjeta deja el foco en ELLA (antes, en <body>)
86+const enfocada = () => p.evaluate(() => { const a = document.activeElement; return a?.classList.contains('model-card') ? a.querySelector('b')?.textContent : (a?.id || a?.tagName); });
87+await p.locator('#settings-panel .model-card', { hasText: 'Básico' }).first().focus();
88+await p.keyboard.press('Enter');
89+await p.waitForTimeout(200);
90+ok('6 · Enter en la tarjeta «Básico» deja el foco en esa tarjeta', /Básico/.test(await enfocada() || ''), await enfocada());
91+await tarjetaQwen.focus();
92+await p.keyboard.press('Enter');
93+await p.waitForTimeout(150);
94+const focoCargando = await enfocada();
95+await p.waitForTimeout(1500);
96+ok('6 · Enter en una tarjeta que carga: el foco sigue en ella durante y después de la carga', /Qwen3.5-0.8B/.test(focoCargando || '') && /Qwen3.5-0.8B/.test(await enfocada() || ''),
97+ JSON.stringify({ focoCargando, despues: await enfocada() }));
7898
7999 // 5 · el punto del modelo
80100 await p.click('#btn-settings'); // cierra
@@ -83,6 +103,9 @@
83103 await p.click('#model-dot');
84104 await p.waitForTimeout(300);
85105 ok('5 · …y lleva a Ajustes', await p.evaluate(() => !document.getElementById('settings-panel').hidden && !!document.querySelector('#settings-panel .model-grid')));
106+ok('5 · …con el foco en la tarjeta del modelo ACTIVO (no en la primera)', await p.evaluate(() =>
107+ document.activeElement?.classList.contains('model-card') && document.activeElement.classList.contains('active') && /Qwen3.5-0.8B/.test(document.activeElement.textContent)),
108+ await p.evaluate(() => document.activeElement?.textContent?.slice(0, 40)));
86109 await ctx.close();
87110
88111 // 1 · Mac sin datos de arquitectura (Safari): las dos versiones
modified web/js/main.js +31 −11
@@ -770,6 +770,8 @@
770770 }
771771
772772 let loadingId = null;
773+// Lo pone renderSettings: repinta las tarjetas de modelo del panel abierto.
774+let repintaTarjetasModelo = () => {};
773775 async function changeModel(id) {
774776 if (id === 'rules') {
775777 conv.setProvider(rules);
@@ -842,6 +844,7 @@
842844 return false;
843845 } finally {
844846 loadingId = null;
847+ repintaTarjetasModelo(); // Ajustes abierto: la activa y el «cargando…» al día
845848 }
846849 }
847850 let _fellBack = false;
@@ -1020,25 +1023,37 @@
10201023 const grid = el('div', 'model-grid');
10211024 grid.setAttribute('role', 'group');
10221025 grid.setAttribute('aria-label', t('setBrainTitle'));
1023- for (const m of LOCAL) {
1024- if (m.need === 'gpu' && !realGPU) continue;
1026+ // Cada tarjeta se pinta aquí y se REPINTA en su sitio (clases, aria-pressed,
1027+ // aria-busy y texto): la misma tarjeta, el mismo foco. Antes elegir un modelo
1028+ // rehacía el panel entero al empezar y otra vez al terminar la carga: lo que
1029+ // estuvieras escribiendo en Ajustes (el feedback, el token del bridge) se
1030+ // borraba y el foco caía a <body> (con Enter, al instante).
1031+ const pintaTarjeta = (card, m) => {
10251032 const cargando = loadingId === m.id;
1026- const card = el('button', 'model-card' + (activeModel === m.id ? ' active' : '') + (m.disabled ? ' disabled' : '') + (cargando ? ' loading' : ''));
1027- if (m.disabled) card.disabled = true;
1033+ card.className = 'model-card' + (activeModel === m.id ? ' active' : '') + (m.disabled ? ' disabled' : '') + (cargando ? ' loading' : '');
10281034 card.setAttribute('aria-pressed', activeModel === m.id ? 'true' : 'false');
1029- if (cargando) card.setAttribute('aria-busy', 'true');
1035+ if (cargando) card.setAttribute('aria-busy', 'true'); else card.removeAttribute('aria-busy');
10301036 card.innerHTML = `<b>${m.name}</b><span>${cargando ? escapeHtml(t('setModelLoadingCard')) : m.sub}</span>`;
1031- // La tarjeta dice «cargando…» mientras carga, y el panel se repinta cuando
1032- // termina: antes se repintaba al instante y el resaltado se quedaba en el
1033- // modelo anterior hasta reabrir Ajustes.
1037+ };
1038+ const tarjetas = [];
1039+ for (const m of LOCAL) {
1040+ if (m.need === 'gpu' && !realGPU) continue;
1041+ const card = el('button', 'model-card');
1042+ card.dataset.model = m.id;
1043+ if (m.disabled) card.disabled = true;
1044+ pintaTarjeta(card, m);
1045+ tarjetas.push([card, m]);
1046+ // La tarjeta dice «cargando…» mientras carga, y la activa cambia cuando
1047+ // termina (changeModel avisa: repintaTarjetasModelo).
10341048 card.onclick = async () => {
10351049 const p = changeModel(m.id);
1036- renderSettings();
1050+ repintaTarjetasModelo();
10371051 await p;
1038- if (!$('settings-panel').hidden && $('settings-panel').querySelector('.model-grid')) renderSettings();
1052+ repintaTarjetasModelo();
10391053 };
10401054 grid.appendChild(card);
10411055 }
1056+ repintaTarjetasModelo = () => { for (const [card, m] of tarjetas) if (card.isConnected) pintaTarjeta(card, m); };
10421057 box.appendChild(grid);
10431058
10441059 // --- Espacio de trabajo: guardar conversaciones/skills en disco ---
@@ -1589,7 +1604,12 @@
15891604 anuncioPendiente = setTimeout(() => { r.textContent = texto; }, 50);
15901605 }
15911606 $('model-select').addEventListener('change', e => changeModel(e.target.value));
1592-$('model-dot').addEventListener('click', () => { renderSettings(); requestAnimationFrame(() => $('settings-panel').querySelector('.model-card.active, .model-card')?.focus()); });
1607+// El foco va a la tarjeta del modelo ACTIVO (un selector con coma devolvía la
1608+// primera tarjeta en el orden del documento, no la activa).
1609+$('model-dot').addEventListener('click', () => {
1610+ renderSettings();
1611+ requestAnimationFrame(() => { const panel = $('settings-panel'); (panel.querySelector('.model-card.active') || panel.querySelector('.model-card'))?.focus(); });
1612+});
15931613 pintaDot('off', 'rules');
15941614 // móvil: conmutar chat ↔ editor
15951615 // ☰ (solo en el móvil): cajón con el árbol de ficheros y la barra de