Skip to content

Commit 9affcd1

Browse files
ianhifcollonval
andauthored
don't use docmanager reload when opening gitignore (#759)
* don't use docmanager reload when opening gitignore this would affect all open widgets, not just the gitignore editor and could result in unsaved changes being lost * Debug binder * Turn off minimization * All actions handle by the model * remove unused import Co-authored-by: Frédéric Collonval <fcollonval@gmail.com>
1 parent 7f3e4cc commit 9affcd1

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

binder/postBuild

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22
pip install .
33
jupyter serverextension enable --sys-prefix --py nbgitpuller
4-
jupyter lab build
4+
jupyter lab build --dev-build=False --minimize=False --debug

src/commandsAndMenu.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { ITerminal } from '@jupyterlab/terminal';
1212
import { CommandRegistry } from '@lumino/commands';
1313
import { Menu } from '@lumino/widgets';
1414
import { IGitExtension } from './tokens';
15-
import { GitExtension } from './model';
1615
import { GitCredentialsForm } from './widgets/CredentialsBox';
1716
import { doGitClone } from './widgets/gitClone';
1817
import { GitPullPushDialog, Operation } from './widgets/gitPushPull';
@@ -199,11 +198,6 @@ export function addCommands(
199198
isEnabled: () => model.pathRepository !== null,
200199
execute: async () => {
201200
await model.ensureGitignore();
202-
const gitModel = model as GitExtension;
203-
await gitModel.commands.execute('docmanager:reload');
204-
await gitModel.commands.execute('docmanager:open', {
205-
path: model.getRelativeFilePath('.gitignore')
206-
});
207201
}
208202
});
209203

src/components/FileList.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
160160
execute: async () => {
161161
if (this.state.selectedFile) {
162162
await this.props.model.ignore(this.state.selectedFile.to, false);
163-
await this.props.model.commands.execute('docmanager:reload');
164-
await this.props.model.commands.execute('docmanager:open', {
165-
path: this.props.model.getRelativeFilePath('.gitignore')
166-
});
167163
}
168164
}
169165
});
@@ -187,10 +183,6 @@ export class FileList extends React.Component<IFileListProps, IFileListState> {
187183
});
188184
if (result.button.label === 'Ignore') {
189185
await this.props.model.ignore(this.state.selectedFile.to, true);
190-
await this.props.model.commands.execute('docmanager:reload');
191-
await this.props.model.commands.execute('docmanager:open', {
192-
path: this.props.model.getRelativeFilePath('.gitignore')
193-
});
194186
}
195187
}
196188
}

src/model.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,7 @@ export class GitExtension implements IGitExtension {
12401240
});
12411241

12421242
this.refreshStatus();
1243+
this._openGitignore();
12431244
return Promise.resolve(response);
12441245
}
12451246

@@ -1271,6 +1272,7 @@ export class GitExtension implements IGitExtension {
12711272
});
12721273

12731274
this.refreshStatus();
1275+
this._openGitignore();
12741276
return Promise.resolve(response);
12751277
}
12761278

@@ -1423,6 +1425,22 @@ export class GitExtension implements IGitExtension {
14231425
return this._taskID;
14241426
}
14251427

1428+
/**
1429+
* open new editor or show an existing editor of the
1430+
* .gitignore file. If the editor does not have unsaved changes
1431+
* then ensure the editor's content matches the file on disk
1432+
*/
1433+
private _openGitignore() {
1434+
if (this._docmanager) {
1435+
const widget = this._docmanager.openOrReveal(
1436+
this.getRelativeFilePath('.gitignore')
1437+
);
1438+
if (widget && !widget.context.model.dirty) {
1439+
widget.context.revert();
1440+
}
1441+
}
1442+
}
1443+
14261444
/**
14271445
* if file is open in JupyterLab find the widget and ensure the JupyterLab
14281446
* version matches the version on disk. Do nothing if the file has unsaved changes

0 commit comments

Comments
 (0)