utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | a173c6d98b7c7136f52202c40d78c2a1a8f6b67ec05c37e7bb3cf1c3ee2cdbd6 |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-10 19:30 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-11 14:15 +02:00 |
| Parents | 5d9d7359c26a |
2 files changed
modified tests/editor-save.mjs +36 −0
| @@ -14,6 +14,10 @@ | ||
| 14 | 14 | // «Copiar ruta» lo dice. |
| 15 | 15 | // 6. El árbol se usa con el teclado (↓ y Enter) y Escape cierra su menú. |
| 16 | 16 | // 7. «Ir a símbolo» sin fichero abierto lo dice en vez de no hacer nada. |
| 17 | +// 8. Guardar una pestaña cuyo fichero se borró lo vuelve a crear Y el | |
| 18 | +// explorador lo enseña (antes quedaba fuera del árbol). | |
| 19 | +// 9. Cerrar una pestaña con el teclado (Supr, o «No guardar») deja el foco en | |
| 20 | +// la pestaña que queda (antes caía a <body>). | |
| 17 | 21 | // |
| 18 | 22 | // BASE=http://127.0.0.1:8898 node tests/editor-save.mjs |
| 19 | 23 | import { chromium } from 'playwright'; |
| @@ -156,6 +160,38 @@ | ||
| 156 | 160 | await p.waitForTimeout(100); |
| 157 | 161 | ok('6 · Shift+F10 abre el menú del árbol y Escape lo cierra', menuAbierto === 1 && await p.locator('#tree-menu').count() === 0); |
| 158 | 162 | |
| 163 | +// 8 · guardar una pestaña cuyo fichero se borró lo vuelve a crear, y el árbol lo enseña | |
| 164 | +await abre('notes/todo.md'); | |
| 165 | +await escribeEnEditor('- otra tarea\n'); | |
| 166 | +await p.locator('#tree .file[data-path="notes/todo.md"]').click({ button: 'right' }); | |
| 167 | +await p.locator('#tree-menu .tm-item', { hasText: 'Eliminar' }).click(); | |
| 168 | +await p.waitForTimeout(400); | |
| 169 | +ok('8 · borrar un fichero con cambios deja su pestaña abierta (marcada)', (await pestañas()).some(t => t.path === 'notes/todo.md'), JSON.stringify(await pestañas())); | |
| 170 | +await p.click('#menubar button[data-menu="file"]'); | |
| 171 | +await p.locator('#topmenu .menu-item', { hasText: 'Guardar' }).click(); | |
| 172 | +await p.waitForTimeout(400); | |
| 173 | +ok('8 · guardarla lo vuelve a crear en disco…', (await disco('notes/todo.md'))?.includes('otra tarea'), String(await disco('notes/todo.md'))); | |
| 174 | +ok('8 · …y el explorador lo enseña otra vez', await p.locator('#tree .file[data-path="notes/todo.md"]').count() === 1); | |
| 175 | + | |
| 176 | +// 9 · cerrar una pestaña con el teclado deja el foco en la pestaña que queda | |
| 177 | +await abre('README.md'); | |
| 178 | +await abre('src/app.js'); | |
| 179 | +await p.locator('#tabs-bar .tab.active').focus(); | |
| 180 | +await p.keyboard.press('Delete'); | |
| 181 | +await p.waitForTimeout(300); | |
| 182 | +const foco9 = await p.evaluate(() => ({ tab: document.activeElement?.classList.contains('tab') ? document.activeElement.dataset.path : null, tag: document.activeElement?.tagName })); | |
| 183 | +ok('9 · Supr en una pestaña la cierra y el foco pasa a la pestaña activa (no a <body>)', !!foco9.tab && foco9.tab !== 'src/app.js', JSON.stringify(foco9)); | |
| 184 | +await abre('src/app.js'); | |
| 185 | +await escribeEnEditor('// sin guardar\n'); | |
| 186 | +await p.locator('#tabs-bar .tab.active').focus(); | |
| 187 | +await p.keyboard.press('Delete'); | |
| 188 | +await p.waitForTimeout(200); | |
| 189 | +await p.keyboard.press('Tab'); // de «Guardar» a «No guardar» | |
| 190 | +await p.keyboard.press('Enter'); | |
| 191 | +await p.waitForTimeout(300); | |
| 192 | +const foco9b = await p.evaluate(() => ({ tab: document.activeElement?.classList.contains('tab') ? document.activeElement.dataset.path : null, tag: document.activeElement?.tagName })); | |
| 193 | +ok('9 · …también tras «No guardar» en el diálogo de cambios', !!foco9b.tab && !(await pestañas()).some(t => t.path === 'src/app.js'), JSON.stringify(foco9b)); | |
| 194 | + | |
| 159 | 195 | // 7 · Ir a símbolo sin fichero abierto |
| 160 | 196 | await p.evaluate(() => { for (const x of document.querySelectorAll('#tabs-bar .tab-x')) x.click(); }); |
| 161 | 197 | await p.waitForTimeout(300); |
modified web/js/ide.js +21 −2
| @@ -216,6 +216,7 @@ | ||
| 216 | 216 | code.invalidateFileList?.(); |
| 217 | 217 | } |
| 218 | 218 | async function saveTab(tab) { |
| 219 | + const recreado = !!tab.deleted; | |
| 219 | 220 | try { |
| 220 | 221 | await writeOwn(tab.path, tab.model.getValue()); |
| 221 | 222 | } catch (e) { |
| @@ -225,6 +226,10 @@ | ||
| 225 | 226 | tab.dirty = false; |
| 226 | 227 | tab.deleted = false; |
| 227 | 228 | renderTabs(); |
| 229 | + // Guardar una pestaña cuyo fichero se había borrado lo vuelve a crear, y el | |
| 230 | + // explorador tiene que enseñarlo: writeOwn no pasa por code.write, que era | |
| 231 | + // quien avisaba al árbol (onFileWritten → refreshTree). | |
| 232 | + if (recreado) await refreshTree(); | |
| 228 | 233 | alertBar(t('saved', { path: tab.path })); |
| 229 | 234 | return true; |
| 230 | 235 | } |
| @@ -282,6 +287,20 @@ | ||
| 282 | 287 | await applyView(); |
| 283 | 288 | return true; |
| 284 | 289 | } |
| 290 | +// Cerrar desde la barra de pestañas (Supr, Cmd/Ctrl+W, la ✕, o «No guardar» en | |
| 291 | +// el diálogo): el foco va a la pestaña que queda activa, o al aviso de «sin | |
| 292 | +// ficheros abiertos» si no queda ninguna. Antes caía a <body> (las pestañas de | |
| 293 | +// conversación ya lo hacían bien; las del editor no). | |
| 294 | +async function closeTabYEnfoca(path) { | |
| 295 | + if (!(await closeTab(path))) return false; // cancelado: el diálogo devuelve el foco a la pestaña | |
| 296 | + const activa = $('tabs-bar')?.querySelector('.tab.active'); | |
| 297 | + if (activa) activa.focus(); | |
| 298 | + else { | |
| 299 | + const vacio = document.getElementById('editor-empty'); | |
| 300 | + if (vacio) { vacio.tabIndex = -1; vacio.focus(); } else editor?.focus(); | |
| 301 | + } | |
| 302 | + return true; | |
| 303 | +} | |
| 285 | 304 | // Varias seguidas («Cerrar otras/todas»): se para en la primera que cancelas. |
| 286 | 305 | async function closeTabs(paths) { |
| 287 | 306 | for (const p of paths) if (!(await closeTab(p))) return false; |
| @@ -346,7 +365,7 @@ | ||
| 346 | 365 | x.tabIndex = -1; |
| 347 | 366 | x.setAttribute('aria-label', t(tb.dirty ? 'closeFileDirty' : 'closeFile', { name: baseOf(tb.path) })); |
| 348 | 367 | x.title = x.getAttribute('aria-label'); |
| 349 | - x.onclick = e => { e.stopPropagation(); closeTab(tb.path); }; | |
| 368 | + x.onclick = e => { e.stopPropagation(); closeTabYEnfoca(tb.path); }; | |
| 350 | 369 | el.append(ico, name, x); |
| 351 | 370 | el.onclick = () => openFile(tb.path); |
| 352 | 371 | el.oncontextmenu = e => { e.preventDefault(); openTabMenu(e.clientX, e.clientY, tb.path); }; |
| @@ -357,7 +376,7 @@ | ||
| 357 | 376 | const next = tabs[(i + (e.key === 'ArrowRight' ? 1 : tabs.length - 1)) % tabs.length]; |
| 358 | 377 | if (next) openFile(next.path).then(() => bar.querySelector('.tab.active')?.focus()); |
| 359 | 378 | } else if (e.key === 'Delete' || ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'w')) { |
| 360 | - e.preventDefault(); closeTab(tb.path); | |
| 379 | + e.preventDefault(); closeTabYEnfoca(tb.path); | |
| 361 | 380 | } else if (e.key === 'ContextMenu' || (e.shiftKey && e.key === 'F10')) { |
| 362 | 381 | e.preventDefault(); const r = el.getBoundingClientRect(); openTabMenu(r.left, r.bottom, tb.path); |
| 363 | 382 | } |