Skip to content

Commit

Permalink
Fix issue #52: do not emit if unchanged (#53)
Browse files Browse the repository at this point in the history
* do not emit if unchanged

* Update snapshots

* Always set _path

* Iterate

* Improve comment

---------

Co-authored-by: martinRenou <[email protected]>
  • Loading branch information
michaelchia and martinRenou authored May 31, 2024
1 parent ea2b559 commit f8bcc54
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 9 deletions.
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */

import {
JupyterFrontEnd,
JupyterFrontEndPlugin
Expand Down Expand Up @@ -71,12 +73,13 @@ const fileBrowserFactory: JupyterFrontEndPlugin<IFileBrowserFactory> = {
});

// check the url in iframe and open
app.restored.then(() => {
app.restored.then(async () => {
const windowPathname = window.location.pathname;
const treeIndex = windowPathname.indexOf('/tree/');
let path = windowPathname.substring(treeIndex + '/tree/'.length);
path = decodeURIComponent(path);
if (path) {
const content = await app.serviceManager.contents.get(path);
if (content.type !== 'directory') {
docManager.open(path);
}
});
Expand All @@ -87,6 +90,7 @@ const fileBrowserFactory: JupyterFrontEndPlugin<IFileBrowserFactory> = {
return widget;
};

// @ts-ignore: DirListing._onPathChanged is private upstream, need to change this so we can remove the ignore
return { createFileBrowser, tracker };
}
};
Expand Down
32 changes: 25 additions & 7 deletions src/unfold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export class FileTreeRenderer extends DirListing.Renderer {
/**
* A widget which hosts a filetree.
*/
// @ts-ignore: _onPathChanged is private upstream, need to change this
export class DirTreeListing extends DirListing {
constructor(options: DirTreeListing.IOptions) {
super({ ...options, renderer: new FileTreeRenderer(options.model) });
Expand Down Expand Up @@ -229,6 +230,11 @@ export class DirTreeListing extends DirListing {
}
}

_onPathChanged(): void {
// It's a no-op to overwrite the base class behavior
// We don't want to deselect everything when the path changes
}

private _eventDragEnter(event: IDragEvent): void {
if (event.mimeData.hasData(CONTENTS_MIME)) {
// @ts-ignore
Expand Down Expand Up @@ -428,16 +434,26 @@ export class FilterFileTreeBrowserModel extends FilterFileBrowserModel {
}

set path(value: string) {
const pathChanged = this.pathChanged as Signal<this, IChangedArgs<string>>;
const oldValue = this._path;
let needsToEmit = false;

if (this._path !== value) {
needsToEmit = true;
}

this._path = value;

pathChanged.emit({
name: 'path',
oldValue,
newValue: value
});
if (needsToEmit) {
const pathChanged = this.pathChanged as Signal<
this,
IChangedArgs<string>
>;

pathChanged.emit({
name: 'path',
oldValue: this._path,
newValue: PathExt.dirname(this._path)
});
}
}

/**
Expand Down Expand Up @@ -665,6 +681,7 @@ export class FileTreeBrowser extends FileBrowser {
}

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

model: FilterFileTreeBrowserModel;

// @ts-ignore: _onPathChanged is private upstream, need to change this
listing: DirTreeListing;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f8bcc54

Please sign in to comment.