From 9ca393b1d68ee8f1249d47e20aa42b053df614e0 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Fri, 16 Mar 2018 16:39:57 +0100 Subject: [PATCH] GH-1479: Fixed bug when moving `Files` from left to right. Also reused disposables from the parent widget. Signed-off-by: Akos Kitta --- packages/navigator/src/browser/navigator-widget.ts | 12 ++++-------- packages/navigator/src/browser/search-box-widget.ts | 8 +------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/navigator/src/browser/navigator-widget.ts b/packages/navigator/src/browser/navigator-widget.ts index 2de35dd5cddbf..88478de00c859 100644 --- a/packages/navigator/src/browser/navigator-widget.ts +++ b/packages/navigator/src/browser/navigator-widget.ts @@ -15,7 +15,6 @@ import { FileTreeWidget, DirNode } from '@theia/filesystem/lib/browser'; import { WorkspaceService, WorkspaceCommands } from '@theia/workspace/lib/browser'; import { FileNavigatorModel } from './navigator-model'; import { FileNavigatorSearch } from './navigator-search'; -import { DisposableCollection } from '@theia/core/lib/common/disposable'; import { SearchBoxWidget, SearchBoxWidgetProps, SearchBoxWidgetFactory } from './search-box-widget'; export const FILE_NAVIGATOR_ID = 'files'; @@ -25,7 +24,6 @@ export const CLASS = 'theia-Files'; @injectable() export class FileNavigatorWidget extends FileTreeWidget { - protected readonly disposables = new DisposableCollection(); protected readonly searchBox: SearchBoxWidget; constructor( @@ -45,7 +43,7 @@ export class FileNavigatorWidget extends FileTreeWidget { this.addClass(CLASS); this.initialize(); this.searchBox = searchBoxFactory(SearchBoxWidgetProps.DEFAULT); - this.disposables.pushAll([ + this.toDispose.pushAll([ this.model.onExpansionChanged(() => this.searchBox.hide()), this.navigatorSearch, this.navigatorSearch.onFilteredNodesChanged(nodes => { @@ -79,11 +77,6 @@ export class FileNavigatorWidget extends FileTreeWidget { }); } - dispose(): void { - super.dispose(); - this.disposables.dispose(); - } - protected deflateForStorage(node: TreeNode): object { // tslint:disable-next-line:no-any const copy = { ...node } as any; @@ -109,6 +102,9 @@ export class FileNavigatorWidget extends FileTreeWidget { super.onAfterAttach(msg); this.addClipboardListener(this.node, 'copy', e => this.handleCopy(e)); this.addClipboardListener(this.node, 'paste', e => this.handlePaste(e)); + if (this.searchBox.isAttached) { + Widget.detach(this.searchBox); + } Widget.attach(this.searchBox, this.node.parentElement!); this.addKeyListener(this.node, this.searchBox.keyCodePredicate.bind(this.searchBox), this.searchBox.handle.bind(this.searchBox)); } diff --git a/packages/navigator/src/browser/search-box-widget.ts b/packages/navigator/src/browser/search-box-widget.ts index a0f05590646e8..7fd8dbbbd72df 100644 --- a/packages/navigator/src/browser/search-box-widget.ts +++ b/packages/navigator/src/browser/search-box-widget.ts @@ -9,7 +9,6 @@ import { inject, injectable } from 'inversify'; import { KeyCode, Key } from '@theia/core/lib/browser'; import { BaseWidget } from '@theia/core/lib/browser/widgets/widget'; import { Event, Emitter } from '@theia/core/lib/common/event'; -import { DisposableCollection } from '@theia/core/lib/common/disposable'; import { SearchThrottle } from './search-throttle'; /** @@ -52,7 +51,6 @@ export class SearchBoxWidget extends BaseWidget { Key.BACKSPACE ]; - protected readonly disposables = new DisposableCollection(); protected readonly nextEmitter = new Emitter(); protected readonly previousEmitter = new Emitter(); protected readonly closeEmitter = new Emitter(); @@ -64,7 +62,7 @@ export class SearchBoxWidget extends BaseWidget { @inject(SearchThrottle) protected readonly throttle: SearchThrottle) { super(); - this.disposables.pushAll([ + this.toDispose.pushAll([ this.nextEmitter, this.previousEmitter, this.closeEmitter, @@ -78,10 +76,6 @@ export class SearchBoxWidget extends BaseWidget { this.input = input; } - dispose() { - this.disposables.dispose(); - } - get onPrevious(): Event { return this.previousEmitter.event; }