show reload alert dialog

This commit is contained in:
codetypes committed 2024-11-21 23:04:39 +08:00
1 parent 78ee7bcc76
commit 1cced07da9
3 files changed
+21 -25

No files matched your search

+9 -11
View File
@@ -51,6 +51,8 @@ export class EditorStore {
dragDstId?: string;
unsave: boolean = false;
modifiedTime: number = Date.now();
alertReload: boolean = false;
historyStack: NodeModel[] = [];
historyIndex: number = 0;
selectedId?: string | null;
@@ -130,9 +132,10 @@ export type WorkspaceStore = {
allFiles: Map<string, FileMeta>;
fileTree?: FileTreeType;
editors: EditorStore[];
modifiedEditors: EditorStore[];
editing?: EditorStore;
modifiedTime: number;
isShowingSearch: boolean;
onShowingSearch: (isShowingSearch: boolean) => void;
@@ -392,6 +395,8 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
}
},
modifiedTime: 0,
isShowingSearch: false,
onShowingSearch: (isShowingSearch) => {
set({ isShowingSearch });
@@ -500,17 +505,10 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
} else {
const fullpath = fs.realpathSync(`${workspace.workdir}/${filename}`);
const editor = workspace.find(fullpath);
if (
editor &&
editor.modifiedTime + 500 < fs.statSync(fullpath).mtimeMs &&
!workspace.modifiedEditors.includes(editor)
) {
if (editor && editor.modifiedTime + 500 < fs.statSync(fullpath).mtimeMs) {
if (editor.unsave) {
const modifiedEditors = workspace.modifiedEditors;
console.log("modified1:", editor.path, modifiedEditors);
modifiedEditors.push(editor);
set({ modifiedEditors: modifiedEditors });
console.log("modified2:", editor.path, modifiedEditors);
editor.alertReload = true;
set({ modifiedTime: Date.now() });
} else {
editor.dispatch("reload");
}