Skip to content

Commit f8bcc54

Browse files
Fix issue #52: do not emit if unchanged (#53)
* do not emit if unchanged * Update snapshots * Always set _path * Iterate * Improve comment --------- Co-authored-by: martinRenou <[email protected]>
1 parent ea2b559 commit f8bcc54

File tree

7 files changed

+31
-9
lines changed

7 files changed

+31
-9
lines changed

src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/ban-ts-comment */
2+
13
import {
24
JupyterFrontEnd,
35
JupyterFrontEndPlugin
@@ -71,12 +73,13 @@ const fileBrowserFactory: JupyterFrontEndPlugin<IFileBrowserFactory> = {
7173
});
7274

7375
// check the url in iframe and open
74-
app.restored.then(() => {
76+
app.restored.then(async () => {
7577
const windowPathname = window.location.pathname;
7678
const treeIndex = windowPathname.indexOf('/tree/');
7779
let path = windowPathname.substring(treeIndex + '/tree/'.length);
7880
path = decodeURIComponent(path);
79-
if (path) {
81+
const content = await app.serviceManager.contents.get(path);
82+
if (content.type !== 'directory') {
8083
docManager.open(path);
8184
}
8285
});
@@ -87,6 +90,7 @@ const fileBrowserFactory: JupyterFrontEndPlugin<IFileBrowserFactory> = {
8790
return widget;
8891
};
8992

93+
// @ts-ignore: DirListing._onPathChanged is private upstream, need to change this so we can remove the ignore
9094
return { createFileBrowser, tracker };
9195
}
9296
};

src/unfold.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export class FileTreeRenderer extends DirListing.Renderer {
191191
/**
192192
* A widget which hosts a filetree.
193193
*/
194+
// @ts-ignore: _onPathChanged is private upstream, need to change this
194195
export class DirTreeListing extends DirListing {
195196
constructor(options: DirTreeListing.IOptions) {
196197
super({ ...options, renderer: new FileTreeRenderer(options.model) });
@@ -229,6 +230,11 @@ export class DirTreeListing extends DirListing {
229230
}
230231
}
231232

233+
_onPathChanged(): void {
234+
// It's a no-op to overwrite the base class behavior
235+
// We don't want to deselect everything when the path changes
236+
}
237+
232238
private _eventDragEnter(event: IDragEvent): void {
233239
if (event.mimeData.hasData(CONTENTS_MIME)) {
234240
// @ts-ignore
@@ -428,16 +434,26 @@ export class FilterFileTreeBrowserModel extends FilterFileBrowserModel {
428434
}
429435

430436
set path(value: string) {
431-
const pathChanged = this.pathChanged as Signal<this, IChangedArgs<string>>;
432-
const oldValue = this._path;
437+
let needsToEmit = false;
438+
439+
if (this._path !== value) {
440+
needsToEmit = true;
441+
}
433442

434443
this._path = value;
435444

436-
pathChanged.emit({
437-
name: 'path',
438-
oldValue,
439-
newValue: value
440-
});
445+
if (needsToEmit) {
446+
const pathChanged = this.pathChanged as Signal<
447+
this,
448+
IChangedArgs<string>
449+
>;
450+
451+
pathChanged.emit({
452+
name: 'path',
453+
oldValue: this._path,
454+
newValue: PathExt.dirname(this._path)
455+
});
456+
}
441457
}
442458

443459
/**
@@ -665,6 +681,7 @@ export class FileTreeBrowser extends FileBrowser {
665681
}
666682

667683
protected createDirListing(options: DirListing.IOptions): DirListing {
684+
// @ts-ignore: _onPathChanged is private upstream, need to change this
668685
return new DirTreeListing({
669686
model: this.model,
670687
translator: this.translator
@@ -677,5 +694,6 @@ export class FileTreeBrowser extends FileBrowser {
677694

678695
model: FilterFileTreeBrowserModel;
679696

697+
// @ts-ignore: _onPathChanged is private upstream, need to change this
680698
listing: DirTreeListing;
681699
}
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)