|
415 | 415 | if (!$activeDocumentIsDirty) { |
416 | 416 | return true; |
417 | 417 | } |
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(); |
424 | 419 | if (decision === 'stay') { |
425 | 420 | return false; |
426 | 421 | } |
|
797 | 792 | return false; |
798 | 793 | } |
799 | 794 |
|
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. */ |
809 | 796 | async function resolveUnsavedChanges( |
810 | 797 | message: string, |
811 | 798 | confirmSaveLabel: string, |
|
829 | 816 | return 'proceed-discarded'; |
830 | 817 | } |
831 | 818 |
|
| 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 | +
|
832 | 829 | async function confirmAndNavigate(filePath: string | null) { |
833 | 830 | if (!(await confirmNavigateAway())) { |
834 | 831 | return false; |
|
1304 | 1301 | ) { |
1305 | 1302 | // Guard against switching away from dirty file |
1306 | 1303 | 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(); |
1313 | 1305 | if (decision === 'stay') { |
1314 | 1306 | return; |
1315 | 1307 | } |
|
0 commit comments