From 00553e24848c14b5686047317f3bb1e7206c7515 Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Wed, 28 Oct 2026 21:21:58 +0800 Subject: [PATCH 1/9] fix: confirm before in-place file switch drops an unsaved draft The merged editor mode rewrites the current tab's path, which remounts the viewer and drops a draft that lives only in that instance. Ask the same unsaved-edit guard the tab close uses; re-opening the current path and native-claimed files do not switch this tab and stay prompt-free. --- src/client/EditorHost.tsx | 16 +++++++++++--- tests/editor-host.spec.tsx | 45 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/client/EditorHost.tsx b/src/client/EditorHost.tsx index 4ba63058..588d329c 100644 --- a/src/client/EditorHost.tsx +++ b/src/client/EditorHost.tsx @@ -30,7 +30,7 @@ import type { Context } from '../context-types.ts' import { api, mediaUrl, type SessionScope } from './api.ts' import { BinaryDownload } from './binary-download.tsx' import { planFirstMatch, planFsReadOutcome, type EditorLoadAction } from './editor-load.ts' -import { clearEditorDirty, setEditorDirty } from './editor-dirty.ts' +import { clearEditorDirty, isEditorDirty, setEditorDirty } from './editor-dirty.ts' import { baseName } from './FileTree.tsx' import { createFrameBatcher } from './frame-batcher.ts' import { openClaimedNativeFile, openSidebarFile } from './sidebar-file.ts' @@ -231,9 +231,19 @@ export function EditorHost(props: { */ const openFile = (absolute: string): void => { if (inPlace) { - if (!openClaimedNativeFile(ctx, scope.sessionId, scope.cwd, absolute)) { - ctx.get('betterSidebar')?.updateTab(tab.id, { path: absolute, title: baseName(absolute) }, scope.sessionId) + // A native tab type claims the file: it opens elsewhere and THIS editor + // keeps its draft, so there is nothing to confirm. + if (openClaimedNativeFile(ctx, scope.sessionId, scope.cwd, absolute)) return + // An in-place switch remounts the viewer, and the draft lives only in + // that instance — ask before dropping it, the same guard the tab close + // uses. Re-opening the current path is not a switch. + if (absolute !== path && isEditorDirty(tab.id, scope.sessionId)) { + const confirmed = typeof window.confirm === 'function' + ? window.confirm(t('closeUnsavedConfirm')) + : false + if (!confirmed) return } + ctx.get('betterSidebar')?.updateTab(tab.id, { path: absolute, title: baseName(absolute) }, scope.sessionId) } else { openSidebarFile(ctx, scope.sessionId, absolute, { cwd: scope.cwd }) } diff --git a/tests/editor-host.spec.tsx b/tests/editor-host.spec.tsx index 3e532bc0..2b9dfe50 100644 --- a/tests/editor-host.spec.tsx +++ b/tests/editor-host.spec.tsx @@ -408,6 +408,51 @@ describe('EditorHost (files window)', () => { } }) + it('in-place mode: switching files confirms before dropping an unsaved draft', () => { + const { store, ctx } = setup() + const service = ctx.betterSidebar + // A viewer holding a draft: its toolbar report feeds the host's dirty + // registry, which is what the switch guard reads. + const DirtyViewer = (viewerProps: FileViewerProps): ReactNode => { + useEffect(() => { + viewerProps.onToolbarState?.({ modes: true, mode: 'edit', dirty: true, editable: true, saveState: 'idle' }) + // Mount-only: this instance's draft is the report above. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) + return null + } + service.registerFileViewer({ + id: 'test:dirty', + exts: ['fake'], + fetchStrategy: 'none', + component: DirtyViewer, + }) + const tabId = 'editor:/tmp/a.fake' + service.openTab({ type: 'editor', title: 'a.fake', path: '/tmp/a.fake', id: tabId }) + const fileTab = (): SidebarTab => + allLeaves(store.getSnapshot().state!.bottomSplits).flatMap(leaf => leaf.tabs) + .find(tab => tab.id === tabId)! + store.setPrefs({ ...store.getPrefs(), editorExplorer: true }) + const { container, unmount } = mountHost(ctx, store, fileTab) + const confirm = vi.spyOn(window, 'confirm').mockReturnValue(false) + try { + const input = container.querySelector('input')! + typeAndCommit(input, '/tmp/b.fake') + // Cancelled: the tab keeps its file (and the mounted draft). + expect(confirm).toHaveBeenCalledTimes(1) + expect(fileTab().path).toBe('/tmp/a.fake') + // Confirmed: the same gesture switches in place. + confirm.mockReturnValue(true) + typeAndCommit(input, '/tmp/b.fake') + expect(confirm).toHaveBeenCalledTimes(2) + expect(fileTab().path).toBe('/tmp/b.fake') + expect(fileTab().title).toBe('b.fake') + } finally { + confirm.mockRestore() + unmount() + } + }) + it('in-place mode: a file another native type claims opens THAT type\'s tab, not the editor (#695)', () => { const { store, ctx } = setup() const service = ctx.betterSidebar From 5981c7f7a3fe1364bc07d7191e7882f2de8ea08c Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Wed, 28 Oct 2026 22:06:24 +0800 Subject: [PATCH 2/9] refactor: share the editor's draft-discard confirm fallback refreshFile and the in-place file switch used the same three-line no-confirm fallback. Extract it once and keep the fallback semantics unchanged; the comment now says the switch reads the same dirty registry as the close guard, not that the fallback is identical. --- src/client/EditorHost.tsx | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/client/EditorHost.tsx b/src/client/EditorHost.tsx index 588d329c..08ba856d 100644 --- a/src/client/EditorHost.tsx +++ b/src/client/EditorHost.tsx @@ -113,6 +113,14 @@ function accepted(pending: Promise): Promise { ) } +/** Ask before a reload/switch drops a draft. A host without confirm blocks + * the action: refusing is recoverable, while silently discarding is not. + * (The tab-close guard intentionally proceeds instead — an unclosable tab + * is worse than one skipped prompt.) */ +function confirmDiscard(message: string): boolean { + return typeof window.confirm === 'function' ? window.confirm(message) : false +} + export function EditorHost(props: { ctx: Context store: SidebarStore @@ -162,12 +170,7 @@ export function EditorHost(props: { // Manual refresh (issue #167 + PR #228): a dirty draft is dropped by the // reload (the editor instance remounts), so confirm before discarding it. const refreshFile = (): void => { - if (toolbar?.dirty === true) { - const confirmed = typeof window.confirm === 'function' - ? window.confirm(t('refreshUnsavedConfirm')) - : false - if (!confirmed) return - } + if (toolbar?.dirty === true && !confirmDiscard(t('refreshUnsavedConfirm'))) return setReloadSeq(sequence => sequence + 1) } @@ -235,14 +238,11 @@ export function EditorHost(props: { // keeps its draft, so there is nothing to confirm. if (openClaimedNativeFile(ctx, scope.sessionId, scope.cwd, absolute)) return // An in-place switch remounts the viewer, and the draft lives only in - // that instance — ask before dropping it, the same guard the tab close - // uses. Re-opening the current path is not a switch. - if (absolute !== path && isEditorDirty(tab.id, scope.sessionId)) { - const confirmed = typeof window.confirm === 'function' - ? window.confirm(t('closeUnsavedConfirm')) - : false - if (!confirmed) return - } + // that instance — ask before dropping it, reading the same dirty + // registry the tab close uses. Re-opening the current path is not a + // switch. + if (absolute !== path && isEditorDirty(tab.id, scope.sessionId) + && !confirmDiscard(t('closeUnsavedConfirm'))) return ctx.get('betterSidebar')?.updateTab(tab.id, { path: absolute, title: baseName(absolute) }, scope.sessionId) } else { openSidebarFile(ctx, scope.sessionId, absolute, { cwd: scope.cwd }) From 9f92bff2452c24b8ddc8a094b431a49702c78113 Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Wed, 28 Oct 2026 22:32:03 +0800 Subject: [PATCH 3/9] test: widen the Windows temp-tree cleanup retry budget The ci-windows lane failed in archive.spec.ts's afterEach with ENOTEMPTY after the test had passed. The same cleanup flaked on 2026-10-15; the existing 10x50 ms retry budget is too short on a loaded runner. Raise it to 30x100 ms; POSIX still succeeds on the first attempt. --- tests/temp-tree.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/temp-tree.ts b/tests/temp-tree.ts index b660cbc5..1ae94736 100644 --- a/tests/temp-tree.ts +++ b/tests/temp-tree.ts @@ -13,6 +13,8 @@ * * `maxRetries` + `retryDelay` is Node's own remedy for exactly this, so every * risky cleanup goes through here instead of repeating the retry inline. + * The same archive cleanup flaked again on 2026-10-28 under a loaded runner, + * so the budget now covers a slower handle release than the original 10×50 ms. * POSIX runs are unaffected: the first attempt succeeds and no retry happens. */ import { rmSync } from 'node:fs' @@ -23,5 +25,5 @@ import { rmSync } from 'node:fs' * @param path - file or directory to remove (missing paths are ignored). */ export function removeTree(path: string): void { - rmSync(path, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 }) + rmSync(path, { recursive: true, force: true, maxRetries: 30, retryDelay: 100 }) } From 50ecb43c5468005eacfdee5f5277be34c7e17c8c Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Thu, 29 Oct 2026 09:10:44 +0800 Subject: [PATCH 4/9] fix(editor): use switch-specific copy for the draft guard --- src/client/EditorHost.tsx | 2 +- src/client/locales-ar.ts | 1 + src/client/locales-de.ts | 1 + src/client/locales-fr.ts | 1 + src/client/locales-hi.ts | 1 + src/client/locales-id.ts | 1 + src/client/locales-it.ts | 1 + src/client/locales-ja.ts | 1 + src/client/locales-ko.ts | 1 + src/client/locales-nl.ts | 1 + src/client/locales-pl.ts | 1 + src/client/locales-pt.ts | 1 + src/client/locales-ru.ts | 1 + src/client/locales-sv.ts | 1 + src/client/locales-th.ts | 1 + src/client/locales-tr.ts | 1 + src/client/locales-vi.ts | 1 + src/client/locales-zh-HK.ts | 1 + src/client/locales-zh-MO.ts | 1 + src/client/locales-zh-TW.ts | 1 + src/client/locales.ts | 2 ++ 21 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/client/EditorHost.tsx b/src/client/EditorHost.tsx index 08ba856d..2f9c3b3b 100644 --- a/src/client/EditorHost.tsx +++ b/src/client/EditorHost.tsx @@ -242,7 +242,7 @@ export function EditorHost(props: { // registry the tab close uses. Re-opening the current path is not a // switch. if (absolute !== path && isEditorDirty(tab.id, scope.sessionId) - && !confirmDiscard(t('closeUnsavedConfirm'))) return + && !confirmDiscard(t('switchUnsavedConfirm'))) return ctx.get('betterSidebar')?.updateTab(tab.id, { path: absolute, title: baseName(absolute) }, scope.sessionId) } else { openSidebarFile(ctx, scope.sessionId, absolute, { cwd: scope.cwd }) diff --git a/src/client/locales-ar.ts b/src/client/locales-ar.ts index 872dd9e9..585df7de 100644 --- a/src/client/locales-ar.ts +++ b/src/client/locales-ar.ts @@ -159,6 +159,7 @@ export const ar: Record = { showInFolder: 'إظهار في المجلد', refreshUnsavedConfirm: 'تغيّر الملف على القرص. سيؤدي التحديث إلى فقدان التعديلات غير المحفوظة. متابعة؟', closeUnsavedConfirm: 'يحتوي هذا الملف على تعديلات غير محفوظة. سيؤدي إغلاق علامة التبويب إلى تجاهلها. المتابعة؟', + switchUnsavedConfirm: 'يحتوي هذا الملف على تعديلات غير محفوظة. سيؤدي تبديل الملف إلى تجاهلها. المتابعة؟', save: 'حفظ', saved: 'تم الحفظ', unsaved: 'غير محفوظ', diff --git a/src/client/locales-de.ts b/src/client/locales-de.ts index 04648f4e..6a559eb8 100644 --- a/src/client/locales-de.ts +++ b/src/client/locales-de.ts @@ -144,6 +144,7 @@ export const de: Record = { showInFolder: 'Im Ordner anzeigen', refreshUnsavedConfirm: 'Die Datei wurde geändert. Beim Aktualisieren gehen ungespeicherte Änderungen verloren. Fortfahren?', closeUnsavedConfirm: 'Diese Datei hat ungespeicherte Änderungen. Beim Schließen des Tabs gehen sie verloren. Fortfahren?', + switchUnsavedConfirm: 'Diese Datei hat ungespeicherte Änderungen. Beim Wechseln der Datei gehen sie verloren. Fortfahren?', save: 'Speichern', saved: 'Gespeichert', unsaved: 'Nicht gespeichert', diff --git a/src/client/locales-fr.ts b/src/client/locales-fr.ts index 880125dd..11f31dfa 100644 --- a/src/client/locales-fr.ts +++ b/src/client/locales-fr.ts @@ -151,6 +151,7 @@ export const fr: Record = { showInFolder: 'Afficher dans le dossier', refreshUnsavedConfirm: 'Le fichier a changé sur le disque. Actualiser supprimera les modifications non enregistrées. Continuer ?', closeUnsavedConfirm: 'Ce fichier contient des modifications non enregistrées. Fermer l\'onglet les perdra. Continuer ?', + switchUnsavedConfirm: 'Ce fichier contient des modifications non enregistrées. Changer de fichier les perdra. Continuer ?', save: 'Enregistrer', saved: 'Enregistré', unsaved: 'Non enregistré', diff --git a/src/client/locales-hi.ts b/src/client/locales-hi.ts index 4024af9e..dc80126c 100644 --- a/src/client/locales-hi.ts +++ b/src/client/locales-hi.ts @@ -158,6 +158,7 @@ export const hi: Record = { showInFolder: 'फ़ोल्डर में दिखाएँ', refreshUnsavedConfirm: 'डिस्क पर फ़ाइल बदल गई है। रीफ़्रेश करने पर असहेज किए गए संपादन खो जाएँगे। जारी रखें?', closeUnsavedConfirm: 'इस फ़ाइल में सहेजे नहीं गए संपादन हैं। टैब बंद करने पर वे हट जाएँगे। जारी रखें?', + switchUnsavedConfirm: 'इस फ़ाइल में सहेजे नहीं गए संपादन हैं। फ़ाइल बदलने पर वे हट जाएँगे। जारी रखें?', save: 'सहेजें', saved: 'सहेजा गया', unsaved: 'असहेजित', diff --git a/src/client/locales-id.ts b/src/client/locales-id.ts index f698faf2..fce62783 100644 --- a/src/client/locales-id.ts +++ b/src/client/locales-id.ts @@ -156,6 +156,7 @@ export const id: Record = { showInFolder: 'Tampilkan di folder', refreshUnsavedConfirm: 'File berubah di disk. Menyegarkan akan membuang edit yang belum disimpan. Lanjutkan?', closeUnsavedConfirm: 'File ini memiliki edit yang belum disimpan. Menutup tab akan membuangnya. Lanjutkan?', + switchUnsavedConfirm: 'File ini memiliki edit yang belum disimpan. Mengganti file akan membuangnya. Lanjutkan?', save: 'Simpan', saved: 'Tersimpan', unsaved: 'Belum disimpan', diff --git a/src/client/locales-it.ts b/src/client/locales-it.ts index 2c8691bb..a82eb565 100644 --- a/src/client/locales-it.ts +++ b/src/client/locales-it.ts @@ -149,6 +149,7 @@ export const it: Record = { showInFolder: 'Mostra nella cartella', refreshUnsavedConfirm: 'Il file è cambiato su disco. Aggiornare scarterà le modifiche non salvate. Continuare?', closeUnsavedConfirm: 'Questo file ha modifiche non salvate. Chiudere la scheda le perderà. Continuare?', + switchUnsavedConfirm: 'Questo file ha modifiche non salvate. Cambiando file le perderai. Continuare?', save: 'Salva', saved: 'Salvato', unsaved: 'Non salvato', diff --git a/src/client/locales-ja.ts b/src/client/locales-ja.ts index 30c6eb5d..ff95807f 100644 --- a/src/client/locales-ja.ts +++ b/src/client/locales-ja.ts @@ -158,6 +158,7 @@ export const ja: Record = { showInFolder: 'フォルダーで表示', refreshUnsavedConfirm: 'ディスク上のファイルが変更されました。更新すると未保存の編集が失われます。続行しますか?', closeUnsavedConfirm: 'このファイルには未保存の編集があります。タブを閉じると破棄されます。続行しますか?', + switchUnsavedConfirm: 'このファイルには未保存の編集があります。ファイルを切り替えると破棄されます。続行しますか?', save: '保存', saved: '保存済み', unsaved: '未保存', diff --git a/src/client/locales-ko.ts b/src/client/locales-ko.ts index cbd47d3b..34efafe9 100644 --- a/src/client/locales-ko.ts +++ b/src/client/locales-ko.ts @@ -150,6 +150,7 @@ export const ko: Record = { showInFolder: '폴더에서 표시', refreshUnsavedConfirm: '디스크의 파일이 변경되었습니다. 새로고침하면 저장되지 않은 편집 내용이 손실됩니다. 계속하시겠습니까?', closeUnsavedConfirm: '이 파일에 저장되지 않은 편집이 있습니다. 탭을 닫으면 삭제됩니다. 계속하시겠습니까?', + switchUnsavedConfirm: '이 파일에 저장되지 않은 편집이 있습니다. 파일을 전환하면 삭제됩니다. 계속하시겠습니까?', save: '저장', saved: '저장됨', unsaved: '저장 안 됨', diff --git a/src/client/locales-nl.ts b/src/client/locales-nl.ts index c40b00ab..1639f396 100644 --- a/src/client/locales-nl.ts +++ b/src/client/locales-nl.ts @@ -156,6 +156,7 @@ export const nl: Record = { showInFolder: 'In map tonen', refreshUnsavedConfirm: 'Het bestand is op schijf gewijzigd. Vernieuwen gooit niet-opgeslagen wijzigingen weg. Doorgaan?', closeUnsavedConfirm: 'Dit bestand heeft niet-opgeslagen wijzigingen. Het sluiten van het tabblad gooit ze weg. Doorgaan?', + switchUnsavedConfirm: 'Dit bestand heeft niet-opgeslagen wijzigingen. Bij het wisselen van bestand gaan ze verloren. Doorgaan?', save: 'Opslaan', saved: 'Opgeslagen', unsaved: 'Niet opgeslagen', diff --git a/src/client/locales-pl.ts b/src/client/locales-pl.ts index c4f0a66b..e0269b3b 100644 --- a/src/client/locales-pl.ts +++ b/src/client/locales-pl.ts @@ -160,6 +160,7 @@ export const pl: Record = { showInFolder: 'Pokaż w folderze', refreshUnsavedConfirm: 'Plik zmienił się na dysku. Odświeżenie odrzuci niezapisane zmiany. Kontynuować?', closeUnsavedConfirm: 'Ten plik ma niezapisane zmiany. Zamknięcie karty je odrzuci. Kontynuować?', + switchUnsavedConfirm: 'Ten plik ma niezapisane zmiany. Przełączenie pliku je odrzuci. Kontynuować?', save: 'Zapisz', saved: 'Zapisano', unsaved: 'Niezapisane', diff --git a/src/client/locales-pt.ts b/src/client/locales-pt.ts index 22c0003f..1014bbae 100644 --- a/src/client/locales-pt.ts +++ b/src/client/locales-pt.ts @@ -141,6 +141,7 @@ export const pt: Record = { showInFolder: 'Mostrar na pasta', refreshUnsavedConfirm: 'O arquivo mudou no disco. Atualizar descartará edições não salvas. Continuar?', closeUnsavedConfirm: 'Este arquivo tem edições não salvas. Fechar a aba irá descartá-las. Continuar?', + switchUnsavedConfirm: 'Este arquivo tem edições não salvas. Trocar de arquivo irá descartá-las. Continuar?', save: 'Salvar', saved: 'Salvo', unsaved: 'Não salvo', diff --git a/src/client/locales-ru.ts b/src/client/locales-ru.ts index 8405d951..08e72bce 100644 --- a/src/client/locales-ru.ts +++ b/src/client/locales-ru.ts @@ -154,6 +154,7 @@ export const ru: Record = { showInFolder: 'Показать в папке', refreshUnsavedConfirm: 'Файл изменился на диске. Обновление отбросит несохранённые изменения. Продолжить?', closeUnsavedConfirm: 'В файле есть несохранённые изменения. Закрытие вкладки их отменит. Продолжить?', + switchUnsavedConfirm: 'В файле есть несохранённые изменения. При переключении файла они будут потеряны. Продолжить?', save: 'Сохранить', saved: 'Сохранено', unsaved: 'Не сохранено', diff --git a/src/client/locales-sv.ts b/src/client/locales-sv.ts index 062e87e4..379e5c0b 100644 --- a/src/client/locales-sv.ts +++ b/src/client/locales-sv.ts @@ -141,6 +141,7 @@ export const sv: Record = { showInFolder: 'Visa i mapp', refreshUnsavedConfirm: 'Filen ändrades på disken. Uppdatering kastar osparade ändringar. Fortsätta?', closeUnsavedConfirm: 'Filen har osparade ändringar. Att stänga fliken kastar dem. Fortsätta?', + switchUnsavedConfirm: 'Filen har osparade ändringar. Att byta fil kastar dem. Fortsätta?', save: 'Spara', saved: 'Sparad', unsaved: 'Osparad', diff --git a/src/client/locales-th.ts b/src/client/locales-th.ts index 5795e7d3..ad4e119b 100644 --- a/src/client/locales-th.ts +++ b/src/client/locales-th.ts @@ -158,6 +158,7 @@ export const th: Record = { showInFolder: 'แสดงในโฟลเดอร์', refreshUnsavedConfirm: 'ไฟล์เปลี่ยนบนดิสก์ การรีเฟรชจะทิ้งการแก้ไขที่ยังไม่ได้บันทึก ดำเนินการต่อหรือไม่', closeUnsavedConfirm: 'ไฟล์นี้มีการแก้ไขที่ยังไม่ได้บันทึก การปิดแท็บจะทิ้งการแก้ไขนั้น ดำเนินการต่อหรือไม่', + switchUnsavedConfirm: 'ไฟล์นี้มีการแก้ไขที่ยังไม่ได้บันทึก การสลับไฟล์จะทิ้งการแก้ไขนั้น ดำเนินการต่อหรือไม่', save: 'บันทึก', saved: 'บันทึกแล้ว', unsaved: 'ยังไม่ได้บันทึก', diff --git a/src/client/locales-tr.ts b/src/client/locales-tr.ts index a16b16d2..2455f71c 100644 --- a/src/client/locales-tr.ts +++ b/src/client/locales-tr.ts @@ -158,6 +158,7 @@ export const tr: Record = { showInFolder: 'Klasörde göster', refreshUnsavedConfirm: 'Dosya diskte değişti. Yenileme kaydedilmemiş düzenlemeleri atar. Devam edilsin mi?', closeUnsavedConfirm: 'Bu dosyada kaydedilmemiş değişiklikler var. Sekmeyi kapatmak bunları atacak. Devam edilsin mi?', + switchUnsavedConfirm: 'Bu dosyada kaydedilmemiş değişiklikler var. Dosya değiştirmek bunları atacak. Devam edilsin mi?', save: 'Kaydet', saved: 'Kaydedildi', unsaved: 'Kaydedilmedi', diff --git a/src/client/locales-vi.ts b/src/client/locales-vi.ts index d7329f36..0772ea9a 100644 --- a/src/client/locales-vi.ts +++ b/src/client/locales-vi.ts @@ -158,6 +158,7 @@ export const vi: Record = { showInFolder: 'Hiển thị trong thư mục', refreshUnsavedConfirm: 'Tệp đã thay đổi trên đĩa. Làm mới sẽ loại bỏ các chỉnh sửa chưa lưu. Tiếp tục?', closeUnsavedConfirm: 'Tệp này có chỉnh sửa chưa lưu. Đóng tab sẽ loại bỏ chúng. Tiếp tục?', + switchUnsavedConfirm: 'Tệp này có chỉnh sửa chưa lưu. Chuyển tệp sẽ loại bỏ chúng. Tiếp tục?', save: 'Lưu', saved: 'Đã lưu', unsaved: 'Chưa lưu', diff --git a/src/client/locales-zh-HK.ts b/src/client/locales-zh-HK.ts index 1de30f78..fee5d88b 100644 --- a/src/client/locales-zh-HK.ts +++ b/src/client/locales-zh-HK.ts @@ -173,6 +173,7 @@ export const zhHK: Record = { showInFolder: '在文件夾中顯示', refreshUnsavedConfirm: '檔案已在磁碟上變更。重新整理會丟失尚未儲存的編輯。繼續?', closeUnsavedConfirm: '此檔案有未儲存的編輯,關閉後將被丟棄。繼續嗎?', + switchUnsavedConfirm: '此檔案有未儲存的編輯,切換檔案將丟棄這些內容。繼續嗎?', save: '儲存', saved: '已儲存', unsaved: '未儲存', diff --git a/src/client/locales-zh-MO.ts b/src/client/locales-zh-MO.ts index dd8f5149..50bd9a4f 100644 --- a/src/client/locales-zh-MO.ts +++ b/src/client/locales-zh-MO.ts @@ -173,6 +173,7 @@ export const zhMO: Record = { showInFolder: '在文件夾中顯示', refreshUnsavedConfirm: '檔案已在磁碟上變更。重新整理會丟失尚未儲存的編輯。繼續?', closeUnsavedConfirm: '此檔案有未儲存的編輯,關閉後將被丟棄。繼續嗎?', + switchUnsavedConfirm: '此檔案有未儲存的編輯,切換檔案將丟棄這些內容。繼續嗎?', save: '儲存', saved: '已儲存', unsaved: '未儲存', diff --git a/src/client/locales-zh-TW.ts b/src/client/locales-zh-TW.ts index 79ea0939..e0e07868 100644 --- a/src/client/locales-zh-TW.ts +++ b/src/client/locales-zh-TW.ts @@ -173,6 +173,7 @@ export const zhTW: Record = { showInFolder: '在資料夾中顯示', refreshUnsavedConfirm: '檔案已在磁碟上變更。重新整理會丟失尚未儲存的編輯。繼續?', closeUnsavedConfirm: '此檔案有未儲存的編輯,關閉後將被丟棄。繼續嗎?', + switchUnsavedConfirm: '此檔案有未儲存的編輯,切換檔案將丟棄這些內容。繼續嗎?', save: '儲存', saved: '已儲存', unsaved: '未儲存', diff --git a/src/client/locales.ts b/src/client/locales.ts index 00f37c4f..9dd1107c 100644 --- a/src/client/locales.ts +++ b/src/client/locales.ts @@ -169,6 +169,7 @@ export const zh = { refresh: '刷新', refreshUnsavedConfirm: '文件已在磁盘更新,刷新将丢弃未保存编辑。继续吗?', closeUnsavedConfirm: '该文件有未保存的编辑,关闭后将丢弃。继续吗?', + switchUnsavedConfirm: '该文件有未保存的编辑,切换文件将丢弃这些内容。继续吗?', save: '保存', saved: '已保存', unsaved: '未保存', @@ -813,6 +814,7 @@ export const en: Record = { refresh: 'Refresh', refreshUnsavedConfirm: 'The file changed on disk. Refreshing will discard unsaved edits. Continue?', closeUnsavedConfirm: 'This file has unsaved edits. Closing the tab will discard them. Continue?', + switchUnsavedConfirm: 'This file has unsaved edits. Switching files will discard them. Continue?', save: 'Save', saved: 'Saved', unsaved: 'Unsaved', From ae71cd05e649ce8200651ffb362910a61bcc67f1 Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Thu, 29 Oct 2026 09:10:44 +0800 Subject: [PATCH 5/9] test(editor): cover the three no-prompt switch branches --- tests/editor-host.spec.tsx | 121 ++++++++++++++++++++++++++++++++----- 1 file changed, 105 insertions(+), 16 deletions(-) diff --git a/tests/editor-host.spec.tsx b/tests/editor-host.spec.tsx index 2b9dfe50..6d8dda3e 100644 --- a/tests/editor-host.spec.tsx +++ b/tests/editor-host.spec.tsx @@ -338,6 +338,25 @@ function typeAndCommit(input: HTMLInputElement, value: string): void { }) } +/** Register a viewer that reports an unsaved draft on mount; its report + * feeds the editor-dirty registry the switch/close guards read. */ +function registerDirtyViewer(service: ReturnType): void { + const DirtyViewer = (viewerProps: FileViewerProps): ReactNode => { + useEffect(() => { + viewerProps.onToolbarState?.({ modes: true, mode: 'edit', dirty: true, editable: true, saveState: 'idle' }) + // Mount-only: this instance's draft is the report above. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []) + return null + } + service.registerFileViewer({ + id: 'test:dirty', + exts: ['fake'], + fetchStrategy: 'none', + component: DirtyViewer, + }) +} + describe('EditorHost (files window)', () => { it('a path-less tab renders the empty-state hint with the tree panel open', () => { const { store, ctx, homeTab } = setup() @@ -411,22 +430,7 @@ describe('EditorHost (files window)', () => { it('in-place mode: switching files confirms before dropping an unsaved draft', () => { const { store, ctx } = setup() const service = ctx.betterSidebar - // A viewer holding a draft: its toolbar report feeds the host's dirty - // registry, which is what the switch guard reads. - const DirtyViewer = (viewerProps: FileViewerProps): ReactNode => { - useEffect(() => { - viewerProps.onToolbarState?.({ modes: true, mode: 'edit', dirty: true, editable: true, saveState: 'idle' }) - // Mount-only: this instance's draft is the report above. - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []) - return null - } - service.registerFileViewer({ - id: 'test:dirty', - exts: ['fake'], - fetchStrategy: 'none', - component: DirtyViewer, - }) + registerDirtyViewer(service) const tabId = 'editor:/tmp/a.fake' service.openTab({ type: 'editor', title: 'a.fake', path: '/tmp/a.fake', id: tabId }) const fileTab = (): SidebarTab => @@ -453,6 +457,91 @@ describe('EditorHost (files window)', () => { } }) + it('in-place mode: re-opening the same path never asks to discard the draft', () => { + const { store, ctx } = setup() + registerDirtyViewer(ctx.betterSidebar) + const tabId = 'editor:/tmp/a.fake' + ctx.betterSidebar.openTab({ type: 'editor', title: 'a.fake', path: '/tmp/a.fake', id: tabId }) + const fileTab = (): SidebarTab => + allLeaves(store.getSnapshot().state!.bottomSplits).flatMap(leaf => leaf.tabs) + .find(tab => tab.id === tabId)! + store.setPrefs({ ...store.getPrefs(), editorExplorer: true }) + const { container, unmount } = mountHost(ctx, store, fileTab) + const confirm = vi.spyOn(window, 'confirm') + try { + typeAndCommit(container.querySelector('input')!, '/tmp/a.fake') + // The same path is not a switch: no prompt, same tab, same file. + expect(confirm).not.toHaveBeenCalled() + expect(fileTab().id).toBe(tabId) + expect(fileTab().path).toBe('/tmp/a.fake') + } finally { + confirm.mockRestore() + unmount() + } + }) + + it('in-place mode: a file another native type claims never asks about the draft', () => { + const { store, ctx } = setup() + const service = ctx.betterSidebar + registerDirtyViewer(service) + const resources: string[] = [] + const claimedCtx = { + betterSidebar: service, + get: (name: string) => { + if (name === 'betterSidebar') return service + if (name === 'sidebarRightTabs') { + return { candidates: (address: string) => address.endsWith('.drawio') ? [{ kind: 'drawio' }] : [{ kind: 'editor' }] } + } + if (name === 'sidebarRight') { + return { openResource: (address: string) => { resources.push(address) } } + } + return undefined + }, + sessions: ctx.sessions, + } as unknown as Context + service.openTab({ type: 'editor', title: 'a.fake', path: '/tmp/a.fake', id: 'editor:/tmp/a.fake', meta: { treeOpen: false } }) + const fileTab = (): SidebarTab => + allLeaves(store.getSnapshot().state!.bottomSplits).flatMap(leaf => leaf.tabs) + .find(tab => tab.path === '/tmp/a.fake')! + store.setPrefs({ ...store.getPrefs(), editorExplorer: true }) + const { container, unmount } = mountHost(claimedCtx, store, fileTab) + const confirm = vi.spyOn(window, 'confirm') + try { + typeAndCommit(container.querySelector('input[placeholder^="File path"]')!, '/tmp/board.drawio') + // The claiming type opens the file elsewhere; this tab keeps its draft, + // so there is nothing to confirm. + expect(confirm).not.toHaveBeenCalled() + expect(resources).toHaveLength(1) + expect(fileTab().path).toBe('/tmp/a.fake') + } finally { + confirm.mockRestore() + unmount() + } + }) + + it('split mode: opening another file never asks about the source draft', () => { + const { store, ctx } = setup() + registerDirtyViewer(ctx.betterSidebar) + ctx.betterSidebar.openTab({ type: 'editor', title: 'a.fake', path: '/tmp/a.fake', id: 'editor:/tmp/a.fake' }) + const fileTab = (): SidebarTab => + allLeaves(store.getSnapshot().state!.bottomSplits).flatMap(leaf => leaf.tabs) + .find(tab => tab.path === '/tmp/a.fake')! + store.setPrefs({ ...store.getPrefs(), editorExplorer: false }) + const { container, unmount } = mountHost(ctx, store, fileTab) + const confirm = vi.spyOn(window, 'confirm') + try { + typeAndCommit(container.querySelector('input[placeholder^="File path"]')!, '/tmp/b.fake') + const tabs = allLeaves(store.getSnapshot().state!.bottomSplits).flatMap(leaf => leaf.tabs) + // Split mode opens a per-path tab; the source tab and its draft stay put. + expect(confirm).not.toHaveBeenCalled() + expect(fileTab().path).toBe('/tmp/a.fake') + expect(tabs.some(tab => tab.path === '/tmp/b.fake')).toBe(true) + } finally { + confirm.mockRestore() + unmount() + } + }) + it('in-place mode: a file another native type claims opens THAT type\'s tab, not the editor (#695)', () => { const { store, ctx } = setup() const service = ctx.betterSidebar From 173e01030a0c46b6207a2c6082d518579c6026d4 Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Thu, 29 Oct 2026 09:28:32 +0800 Subject: [PATCH 6/9] fix(i18n): align the switch-file confirm with each language's sibling copy --- src/client/locales-it.ts | 2 +- src/client/locales-nl.ts | 2 +- src/client/locales-ru.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/locales-it.ts b/src/client/locales-it.ts index a82eb565..1351a10b 100644 --- a/src/client/locales-it.ts +++ b/src/client/locales-it.ts @@ -149,7 +149,7 @@ export const it: Record = { showInFolder: 'Mostra nella cartella', refreshUnsavedConfirm: 'Il file è cambiato su disco. Aggiornare scarterà le modifiche non salvate. Continuare?', closeUnsavedConfirm: 'Questo file ha modifiche non salvate. Chiudere la scheda le perderà. Continuare?', - switchUnsavedConfirm: 'Questo file ha modifiche non salvate. Cambiando file le perderai. Continuare?', + switchUnsavedConfirm: 'Questo file ha modifiche non salvate. Cambiare file le perderà. Continuare?', save: 'Salva', saved: 'Salvato', unsaved: 'Non salvato', diff --git a/src/client/locales-nl.ts b/src/client/locales-nl.ts index 1639f396..dd5755f6 100644 --- a/src/client/locales-nl.ts +++ b/src/client/locales-nl.ts @@ -156,7 +156,7 @@ export const nl: Record = { showInFolder: 'In map tonen', refreshUnsavedConfirm: 'Het bestand is op schijf gewijzigd. Vernieuwen gooit niet-opgeslagen wijzigingen weg. Doorgaan?', closeUnsavedConfirm: 'Dit bestand heeft niet-opgeslagen wijzigingen. Het sluiten van het tabblad gooit ze weg. Doorgaan?', - switchUnsavedConfirm: 'Dit bestand heeft niet-opgeslagen wijzigingen. Bij het wisselen van bestand gaan ze verloren. Doorgaan?', + switchUnsavedConfirm: 'Dit bestand heeft niet-opgeslagen wijzigingen. Het wisselen van bestand gooit ze weg. Doorgaan?', save: 'Opslaan', saved: 'Opgeslagen', unsaved: 'Niet opgeslagen', diff --git a/src/client/locales-ru.ts b/src/client/locales-ru.ts index 08e72bce..7795d7fb 100644 --- a/src/client/locales-ru.ts +++ b/src/client/locales-ru.ts @@ -154,7 +154,7 @@ export const ru: Record = { showInFolder: 'Показать в папке', refreshUnsavedConfirm: 'Файл изменился на диске. Обновление отбросит несохранённые изменения. Продолжить?', closeUnsavedConfirm: 'В файле есть несохранённые изменения. Закрытие вкладки их отменит. Продолжить?', - switchUnsavedConfirm: 'В файле есть несохранённые изменения. При переключении файла они будут потеряны. Продолжить?', + switchUnsavedConfirm: 'В файле есть несохранённые изменения. При переключении на другой файл они будут отброшены. Продолжить?', save: 'Сохранить', saved: 'Сохранено', unsaved: 'Не сохранено', From 10ccebb052d01036e65cf15d234a55847cd0234e Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Thu, 29 Oct 2026 10:22:14 +0800 Subject: [PATCH 7/9] test: let detached archive packs land before cleanup --- tests/archive.spec.ts | 6 +++++- tests/temp-tree.ts | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/archive.spec.ts b/tests/archive.spec.ts index 7b470512..e0d47664 100644 --- a/tests/archive.spec.ts +++ b/tests/archive.spec.ts @@ -268,12 +268,16 @@ beforeEach(() => { }) afterEach(async () => { + // `start()` launches `pack()` detached; give its open/spawn a beat to land + // before dispose kills the child. Disposing first lets a late open create a + // temp file AFTER the cleanup below has already walked the tree. + await new Promise(resolve => setTimeout(resolve, 50)) // Before the mocks go: `dispose()` kills through a fake whose `kill` is a // `vi.fn`, and those implementations do not survive a restore. for (const tasks of tables.splice(0)) tasks.dispose() // A killed child closes asynchronously; let the close land (and the packer // close its descriptor) before the directories underneath it disappear. - await new Promise(resolve => setTimeout(resolve, 0)) + await new Promise(resolve => setTimeout(resolve, 50)) for (const [key, value] of Object.entries(savedTmp)) { if (value === undefined) delete process.env[key] else process.env[key] = value diff --git a/tests/temp-tree.ts b/tests/temp-tree.ts index 1ae94736..35515f0b 100644 --- a/tests/temp-tree.ts +++ b/tests/temp-tree.ts @@ -14,7 +14,8 @@ * `maxRetries` + `retryDelay` is Node's own remedy for exactly this, so every * risky cleanup goes through here instead of repeating the retry inline. * The same archive cleanup flaked again on 2026-10-28 under a loaded runner, - * so the budget now covers a slower handle release than the original 10×50 ms. + * so the budget now covers a slower handle release than the original 10×50 ms; + * the Windows lane still hit it once on 2026-10-29, hence the 6 s budget. * POSIX runs are unaffected: the first attempt succeeds and no retry happens. */ import { rmSync } from 'node:fs' @@ -25,5 +26,5 @@ import { rmSync } from 'node:fs' * @param path - file or directory to remove (missing paths are ignored). */ export function removeTree(path: string): void { - rmSync(path, { recursive: true, force: true, maxRetries: 30, retryDelay: 100 }) + rmSync(path, { recursive: true, force: true, maxRetries: 60, retryDelay: 100 }) } From 3d44985f5095fb9d363ef9d70b06cafbec9e3c66 Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Thu, 29 Oct 2026 10:33:12 +0800 Subject: [PATCH 8/9] chore: retrigger CI after an unrelated plugin-mount e2e flake From 6caec31d8306b3cc96684ebda23c69b226a92411 Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Thu, 29 Oct 2026 10:47:58 +0800 Subject: [PATCH 9/9] test: give the aggregate-auth shell probe a Windows-sized timeout --- tests/e2e-aggregate-auth.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/e2e-aggregate-auth.spec.ts b/tests/e2e-aggregate-auth.spec.ts index 56ec9ebd..1833bca7 100644 --- a/tests/e2e-aggregate-auth.spec.ts +++ b/tests/e2e-aggregate-auth.spec.ts @@ -36,7 +36,9 @@ curl() { } ${script.slice(start)} `], { - encoding: 'utf8', timeout: 5_000, + // A ceiling, not a budget: the script is fast, but a loaded Windows + // runner can take seconds just to start bash (status: null on timeout). + encoding: 'utf8', timeout: 15_000, env: { ...process.env, ROOT: root, SCRATCH: scratch, TEST_LAUNCH_URL: launch }, }) expect(result.stderr).toBe('')