Skip to content

Commit 3676d20

Browse files
DonJayamannerchiodo
authored andcommitted
Prompt selecting a file to save once (#8590)
* Prompt selecting a file to save once * Better algorithm
1 parent 2cf5346 commit 3676d20

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

news/2 Fixes/8138.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensure clicking `ctrl+s` in a new `notebook` prompts the user to select a file once instead of twice.

src/client/datascience/interactive-ipynb/nativeEditor.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
8383
private loadedPromise: Deferred<void> = createDeferred<void>();
8484
private _file: Uri = Uri.file('');
8585
private _dirty: boolean = false;
86+
private isPromptingToSaveToDisc: boolean = false;
8687
private visibleCells: ICell[] = [];
8788
private startupTimer: StopWatch = new StopWatch();
8889
private loadedAllCells: boolean = false;
@@ -837,12 +838,18 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
837838

838839
@captureTelemetry(Telemetry.Save, undefined, true)
839840
private async saveToDisk(): Promise<void> {
841+
// If we're already in the middle of prompting the user to save, then get out of here.
842+
// We could add a debounce decorator, unfortunately that slows saving (by waiting for no more save events to get sent).
843+
if (this.isPromptingToSaveToDisc && this.isUntitled) {
844+
return;
845+
}
840846
try {
841847
let fileToSaveTo: Uri | undefined = this.file;
842848
let isDirty = this._dirty;
843849

844850
// Ask user for a save as dialog if no title
845851
if (this.isUntitled) {
852+
this.isPromptingToSaveToDisc = true;
846853
const filtersKey = localize.DataScience.dirtyNotebookDialogFilter();
847854
const filtersObject: { [name: string]: string[] } = {};
848855
filtersObject[filtersKey] = ['ipynb'];
@@ -865,6 +872,8 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
865872
}
866873
} catch (e) {
867874
traceError(e);
875+
} finally {
876+
this.isPromptingToSaveToDisc = false;
868877
}
869878
}
870879

0 commit comments

Comments
 (0)