Skip to content

Commit 151d535

Browse files
committed
Refactor
1 parent 065a810 commit 151d535

1 file changed

Lines changed: 13 additions & 21 deletions

File tree

src/routes/workspaces/[workspaceId]/+page.svelte

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,7 @@
415415
if (!$activeDocumentIsDirty) {
416416
return true;
417417
}
418-
const decision = await resolveUnsavedChanges(
419-
'There are unsaved changes. What would you like to do before navigating away from the current file?',
420-
'Save and Navigate',
421-
'Discard and Navigate',
422-
'Keep Editing',
423-
);
418+
const decision = await resolveUnsavedChangesBeforeFileSwitch();
424419
if (decision === 'stay') {
425420
return false;
426421
}
@@ -797,15 +792,7 @@
797792
return false;
798793
}
799794
800-
/**
801-
* Prompts the user about unsaved changes and resolves the save/discard decision so callers
802-
* don't have to reimplement the modal + save-attempt dance. Returns:
803-
* - 'stay': user cancelled, or chose Save but the save failed/was cancelled — do not navigate.
804-
* - 'proceed-saved': document was saved (and marked clean); safe to navigate.
805-
* - 'proceed-discarded': user chose to discard; caller decides whether to revert content.
806-
* Callers own the post-decision action (goto / replaceState / content-mode switch) and any
807-
* discard-time content revert, since those differ per call site.
808-
*/
795+
/** Shared core for the unsaved-changes prompt; prefer the context-specific wrappers below. */
809796
async function resolveUnsavedChanges(
810797
message: string,
811798
confirmSaveLabel: string,
@@ -829,6 +816,16 @@
829816
return 'proceed-discarded';
830817
}
831818
819+
/** Unsaved-changes prompt for navigating away from the current file (in-page file/mode switch). */
820+
function resolveUnsavedChangesBeforeFileSwitch() {
821+
return resolveUnsavedChanges(
822+
'There are unsaved changes. What would you like to do before navigating away from the current file?',
823+
'Save and Navigate',
824+
'Discard and Navigate',
825+
'Keep Editing',
826+
);
827+
}
828+
832829
async function confirmAndNavigate(filePath: string | null) {
833830
if (!(await confirmNavigateAway())) {
834831
return false;
@@ -1304,12 +1301,7 @@
13041301
) {
13051302
// Guard against switching away from dirty file
13061303
if ($workspaceContentMode === WorkspaceContentMode.File && $activeDocumentIsDirty) {
1307-
const decision = await resolveUnsavedChanges(
1308-
'There are unsaved changes. What would you like to do before navigating away from the current file?',
1309-
'Save and Navigate',
1310-
'Discard and Navigate',
1311-
'Keep Editing',
1312-
);
1304+
const decision = await resolveUnsavedChangesBeforeFileSwitch();
13131305
if (decision === 'stay') {
13141306
return;
13151307
}

0 commit comments

Comments
 (0)