fix: an unsaved edit in a terminal file is lost when another chat is opened (#34135)

* fix: an unsaved edit in a terminal file is lost when another chat is opened

An edit typed into a file opened from the terminal's Files tab and not saved yet was gone after opening another chat and coming back: the file's tab showed the last saved version and lost its unsaved mark, without any warning. The app keeps such an edit in memory when you leave a chat, but a second copy taken while the chat was being closed, when the editor was already gone, overwrote it with one that had no edit in it. Now the edit and its unsaved mark are back when you return to the chat, the same as after switching to another tab in the same chat.

Fixes #34107

* fix: a workbook saved while leaving the chat comes back on its first worksheet

When a workbook save was still running as you switched to another chat, the workbook came back on its first worksheet instead of the one you had open. The late save result now keeps the rest of the file's view, so the worksheet you were on is still selected when you return.

* fix: an unsaved edit in a terminal file is lost when another chat is opened

Shortens the note on why the file view keeps its last full state after the chat is closed.

* Say why the view is reused after teardown

* Name the kept view like the file's other remembered values
This commit is contained in:
Classic298 authored and GitHub committed 2026-11-17 00:55:26 +09:00
1 parent 14618e3553
commit 4e47a27100
1 file changed
+5 -1
+5 -1
View File
@@ -87,7 +87,10 @@
export let onViewChange: ((view: any) => void) | null = null;
export let onFileSaved: ((content: string) => void) | null = null;
let viewRestored = !initialView;
let lastView: any = null;
export const captureView = () => {
// The editor is gone after teardown; a fresh capture would drop its unsaved edit.
if (disposed) return lastView;
const view =
!viewRestored && initialView
? initialView
@@ -99,10 +102,11 @@
dirty: dirty || saving,
scrollTop: viewerRoot?.scrollTop ?? 0
};
return {
lastView = {
...view,
isHome: homeDirectory !== null && asDirectoryPath(view.directory) === homeDirectory
};
return lastView;
};
const restoreView = async () => {
if (disposed || viewRestored || !initialView) return;