Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #52: do not emit if unchanged #53

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading