Elffuss BraidHub

utopia-ia/elffuss-code public

3D views: the editor underneath is inert and focus goes into the view

The Architecture and City views draw an overlay exactly over the editor (and
the terminal, when it is open), but nothing moved focus into it or took the
editor out of reach. From the button that opened a view, Tab went through the
activity bar, the tree and the editor tab, then into the Monaco editor hidden
behind the overlay, and every further Tab indented the open file without the
user seeing it. The searchable list of the view was never reached with a
forward Tab.

While a view is open the editor and the terminal panel are inert, and once
the view is drawn focus goes to its search box (to its close button on
touch screens, where focusing the box would bring up the keyboard over the
list). It does not take focus from a text field the user went to meanwhile.
Closing with Escape or the close button returns focus to whatever opened the
view, or to its activity-bar button when that is gone (a closed menu), or to
the drawer button on phones. modal.js is not used: it makes everything
outside the layer inert, and the view only covers the editor, so the
activity bar, the tree and the chat stay usable.

tests/view-list.mjs, parts 3 and 4: Enter on Architecture puts focus in the
search box with the editor inert; fourteen Tabs from the button reach the view
and never the editor, and the file is unchanged; Escape closes it, returns
focus to the button and the editor is usable again; the City behaves the same;
the close button releases the editor; and on a phone focus lands on the close
button. Against the previous main.js 5 of these checks fail.
Changeset074b411115db14e750c79043cb764821546f0b80a5cf64de50c3cce35f36d62e
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-11 17:33 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 17:33 +02:00
Parents480b615bc50f

Browse the files at this changeset

2 files changed

modified tests/view-list.mjs +81 −0
@@ -4,6 +4,10 @@
44 // vista. Antes solo había el lienzo: con teclado o lector de pantalla no se
55 // podía llegar a ningún fichero desde ahí.
66 //
7+// Y la vista tapa el editor de verdad (partes 3 y 4): el foco entra en ella, el
8+// editor de debajo queda inerte (el Tab no lo alcanza ni lo edita a ciegas) y al
9+// cerrarla el foco vuelve a quien la abrió.
10+//
711 // BASE=http://localhost:8799 node tests/view-list.mjs
812 import { chromium } from 'playwright';
913 const BASE = process.env.BASE || 'http://localhost:8799';
@@ -77,6 +81,83 @@
7781 const tab2 = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => '');
7882 ok('2 · clic en una fila abre ese fichero', await p.locator('#view-overlay').isHidden() && tab2 === 'notas.md', tab2);
7983
84+// 3 · Con teclado, la vista tapa el editor DE VERDAD. Antes el foco se quedaba en
85+// el botón y el Tab, tras la barra, el árbol y la pestaña, caía en el editor
86+// tapado: cada Tab sangraba el fichero sin que se viera, y la lista no se
87+// alcanzaba nunca con Tab hacia delante.
88+{
89+ await p.evaluate(async () => { await (await import('/js/ide.js')).openFile('src/app.js'); });
90+ await p.waitForTimeout(500);
91+ const fichero = () => p.evaluate(() => window.monaco.editor.getEditors()[0].getModel().getValue());
92+ const antes = await fichero();
93+ await p.focus('#act-arch');
94+ await p.keyboard.press('Enter');
95+ await p.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {});
96+ await p.waitForTimeout(300);
97+ const alAbrir = await p.evaluate(() => ({
98+ foco: document.activeElement?.className, editorInerte: document.getElementById('editor').inert,
99+ }));
100+ ok('3 · Enter en Arquitectura: el foco entra en la vista (el buscador) y el editor de debajo queda inerte',
101+ alAbrir.foco === 'vl-filter' && alAbrir.editorInerte === true, JSON.stringify(alAbrir));
102+ await p.focus('#act-arch');
103+ const paradas = [];
104+ for (let i = 0; i < 14; i++) {
105+ await p.keyboard.press('Tab');
106+ paradas.push(await p.evaluate(() => {
107+ const a = document.activeElement;
108+ return a?.closest('.monaco-editor') ? 'EDITOR' : a?.closest('#view-overlay') ? 'VISTA' : (a?.id || a?.tagName);
109+ }));
110+ }
111+ const despues = await fichero();
112+ const pestana = await p.locator('#tabs-bar .tab.active').getAttribute('aria-label').catch(() => '');
113+ ok('3 · Tab desde el botón llega a la lista de la vista y nunca al editor tapado',
114+ paradas.includes('VISTA') && !paradas.includes('EDITOR'), paradas.join(' › '));
115+ ok('3 · …y el fichero de debajo no cambia', despues === antes && !/sin guardar|unsaved/.test(pestana || ''), `${JSON.stringify(despues.slice(0, 30))} · ${pestana}`);
116+ await p.focus('.view-list .vl-filter');
117+ await p.keyboard.press('Escape');
118+ await p.waitForTimeout(300);
119+ const alCerrar = await p.evaluate(() => ({
120+ oculta: document.getElementById('view-overlay').hidden, foco: document.activeElement?.id,
121+ editorInerte: document.getElementById('editor').inert,
122+ }));
123+ ok('3 · Escape la cierra, el foco vuelve al botón y el editor vuelve a ser usable',
124+ alCerrar.oculta && alCerrar.foco === 'act-arch' && alCerrar.editorInerte === false, JSON.stringify(alCerrar));
125+ await p.focus('#act-city');
126+ await p.keyboard.press('Enter');
127+ await p.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {});
128+ await p.waitForTimeout(300);
129+ const ciudad = await p.evaluate(() => ({ foco: document.activeElement?.className, editorInerte: document.getElementById('editor').inert }));
130+ ok('3 · la Ciudad igual: foco en su buscador y el editor inerte', ciudad.foco === 'vl-filter' && ciudad.editorInerte === true, JSON.stringify(ciudad));
131+ await p.click('#view-close');
132+ await p.waitForTimeout(300);
133+ ok('3 · ✕ con el ratón también la cierra y suelta el editor',
134+ await p.evaluate(() => document.getElementById('view-overlay').hidden && !document.getElementById('editor').inert));
135+}
136+
137+// 4 · En el móvil el foco entra en la vista por su ✕, no por el buscador:
138+// enfocar el buscador sacaría el teclado encima de la lista.
139+{
140+ const mctx = await b.newContext({ locale: 'es-ES', viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true });
141+ await mctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
142+ const m = await mctx.newPage();
143+ m.on('pageerror', e => errs.push('móvil: ' + e.message.slice(0, 160)));
144+ await m.goto(BASE + '/manifest.json');
145+ await m.evaluate(async () => {
146+ const o = await navigator.storage.getDirectory();
147+ const f = await o.getFileHandle('index.js', { create: true }); const s = await f.createWritable(); await s.write("export const a = 1;"); await s.close();
148+ });
149+ await m.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
150+ await m.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 20000 });
151+ await m.tap('#btn-drawer');
152+ await m.waitForTimeout(300);
153+ await m.tap('#act-arch');
154+ await m.waitForSelector('#view-body .view-list', { timeout: 30000 }).catch(() => {});
155+ await m.waitForTimeout(300);
156+ const movil = await m.evaluate(() => ({ foco: document.activeElement?.id || document.activeElement?.className, editorInerte: document.getElementById('editor').inert }));
157+ ok('4 · móvil: el foco entra en la vista por su ✕ y el editor queda inerte', movil.foco === 'view-close' && movil.editorInerte === true, JSON.stringify(movil));
158+ await mctx.close();
159+}
160+
80161 console.log('\n errores JS:', errs[0] || 'ninguno');
81162 ok('sin errores de página', errs.length === 0, errs.join(' | '));
82163 console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ VISTAS 3D CON LISTA: se buscan, se recorren y abren con el teclado');
modified web/js/main.js +30 −1
@@ -1824,9 +1824,30 @@
18241824 $('act-arch').innerHTML = UI.graph || UI.code;
18251825 $('act-city').innerHTML = UI.city || UI.code;
18261826 let viewRenderSeq = 0;
1827+// La vista tapa el editor (y el terminal, si está abierto): mientras se ve, lo
1828+// de debajo queda INERTE y el foco entra en ella. Antes el foco se quedaba en el
1829+// botón que la abría, y el Tab, tras la barra de actividad, el árbol y la
1830+// pestaña del editor, caía en el editor TAPADO: cada Tab sangraba el fichero
1831+// abierto sin que se viera, y la lista de la vista no se alcanzaba nunca. (La
1832+// Mente usa modal.js porque tapa la página entera; la vista solo tapa el
1833+// editor, y la barra de actividad, el árbol y el chat siguen a mano.)
1834+const TAPADO_POR_VISTA = ['editor', 'terminal-panel'];
1835+const tapaVista = si => { for (const id of TAPADO_POR_VISTA) { const e = $(id); if (e) e.inert = si; } };
1836+let abridorVista = null;
1837+function seVe(e) { return !!e && e !== document.body && e.isConnected && e.getClientRects().length > 0; }
1838+function entraEnVista(overlay) {
1839+ // Si mientras se montaba el usuario se puso a escribir en otro sitio (el
1840+ // chat), no se le quita el foco.
1841+ const a = document.activeElement;
1842+ if (a && a !== document.body && !overlay.contains(a) && seVe(a) && a.matches('input, textarea, select, [contenteditable]')) return;
1843+ // En el móvil, enfocar el buscador sacaría el teclado encima de la lista.
1844+ const destino = (!matchMedia('(pointer: coarse)').matches && overlay.querySelector('.vl-filter')) || $('view-close');
1845+ try { destino.focus({ preventScroll: true }); } catch { /* — */ }
1846+}
18271847 async function openView(kind) {
18281848 const overlay = $('view-overlay'), body = $('view-body');
18291849 const seq = ++viewRenderSeq;
1850+ if (!overlay.contains(document.activeElement)) abridorVista = document.activeElement;
18301851 // destruir CUALQUIER vista previa (su RAF/canvas seguía vivo al cambiar → la
18311852 // nueva no cargaba bien). Ambas, no solo la del mismo tipo.
18321853 try { (await import('./city.js')).disposeCity(); } catch { /* */ }
@@ -1834,6 +1855,7 @@
18341855 body.innerHTML = '<div class="view-loading" role="status"></div>';
18351856 body.firstChild.textContent = t('viewBuilding');
18361857 overlay.hidden = false;
1858+ tapaVista(true);
18371859 document.querySelectorAll('#activity button').forEach(b => b.classList.toggle('on', b.id === 'act-' + kind));
18381860 // esperar a que el layout dé tamaño real al overlay (si no, canvas 0×0/mal aspect)
18391861 await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r)));
@@ -1845,6 +1867,7 @@
18451867 else { const m = await import('./city.js'); vista = await m.renderCity(body, abre); }
18461868 if (seq === viewRenderSeq) montaListaVista(body, vista, abre);
18471869 } catch (e) { body.innerHTML = '<div class="view-loading" role="status"></div>'; body.firstChild.textContent = t('viewFailed', { e: e?.message || e }); }
1870+ if (seq === viewRenderSeq && !overlay.hidden) entraEnVista(overlay);
18481871 }
18491872
18501873 // Lo que hay en la vista 3D, también como LISTA que se busca y se recorre con
@@ -1921,10 +1944,16 @@
19211944 function closeView({ foco = false } = {}) {
19221945 const abierta = [...document.querySelectorAll('#act-arch.on, #act-city.on')][0];
19231946 $('view-overlay').hidden = true;
1947+ tapaVista(false);
19241948 import('./city.js').then(m => m.disposeCity()).catch(() => {});
19251949 import('./arch.js').then(m => m.disposeArch()).catch(() => {});
19261950 document.querySelectorAll('#activity button').forEach(b => b.classList.toggle('on', b.id === 'act-files'));
1927- if (foco) abierta?.focus();
1951+ // El foco vuelve a quien la abrió si aún se ve; si no (un menú que ya se
1952+ // cerró), al botón de la vista en la barra de actividad; en el móvil, donde
1953+ // esos botones viven en el cajón cerrado, al ☰.
1954+ const vuelta = [abridorVista, abierta, $('btn-drawer'), $('prompt')].find(seVe);
1955+ abridorVista = null;
1956+ if (foco) vuelta?.focus();
19281957 }
19291958 $('act-arch').addEventListener('click', () => openView('arch'));
19301959 $('act-city').addEventListener('click', () => openView('city'));