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

explorer: for collapsing directories react on keydown events #69787

Merged
merged 1 commit into from
Mar 4, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/vs/base/browser/ui/tree/asyncDataTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ export class AsyncDataTree<TInput, T, TFilterData = void> implements IDisposable
get onDidChangeSelection(): Event<ITreeEvent<T>> { return Event.map(this.tree.onDidChangeSelection, asTreeEvent); }
get onDidOpen(): Event<ITreeEvent<T>> { return Event.map(this.tree.onDidOpen, asTreeEvent); }

get onKeyDown(): Event<KeyboardEvent> { return this.tree.onKeyDown; }
get onMouseClick(): Event<ITreeMouseEvent<T>> { return Event.map(this.tree.onMouseClick, asTreeMouseEvent); }
get onMouseDblClick(): Event<ITreeMouseEvent<T>> { return Event.map(this.tree.onMouseDblClick, asTreeMouseEvent); }
get onContextMenu(): Event<ITreeContextMenuEvent<T>> { return Event.map(this.tree.onContextMenu, asTreeContextMenuEvent); }
Expand Down
23 changes: 16 additions & 7 deletions src/vs/workbench/contrib/files/browser/views/explorerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ import { IStorageService, StorageScope } from 'vs/platform/storage/common/storag
import { IAsyncDataTreeViewState } from 'vs/base/browser/ui/tree/asyncDataTree';
import { FuzzyScore } from 'vs/base/common/filters';
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
import { isMacintosh } from 'vs/base/common/platform';
import { KeyCode } from 'vs/base/common/keyCodes';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';

export class ExplorerView extends ViewletPanel {
static readonly ID: string = 'workbench.explorer.fileView';
Expand Down Expand Up @@ -324,14 +327,9 @@ export class ExplorerView extends ViewletPanel {
const shiftDown = e.browserEvent instanceof KeyboardEvent && e.browserEvent.shiftKey;
if (selection.length === 1 && !shiftDown) {
// Do not react if user is clicking on explorer items which are input placeholders
if (!selection[0].name) {
if (!selection[0].name || selection[0].isDirectory) {
// Do not react if user is clicking on explorer items which are input placeholders
return;
}
if (selection[0].isDirectory) {
if (e.browserEvent instanceof KeyboardEvent) {
this.tree.toggleCollapsed(selection[0]);
}
// Do not react if clicking on directories
return;
}

Expand All @@ -347,6 +345,17 @@ export class ExplorerView extends ViewletPanel {
}));

this.disposables.push(this.tree.onContextMenu(e => this.onContextMenu(e)));
this.disposables.push(this.tree.onKeyDown(e => {
const event = new StandardKeyboardEvent(e);
const toggleCollapsed = isMacintosh ? (event.keyCode === KeyCode.DownArrow && event.metaKey) : event.keyCode === KeyCode.Enter;
if (toggleCollapsed) {
const focus = this.tree.getFocus();
if (focus.length === 1 && focus[0].isDirectory) {
this.tree.toggleCollapsed(focus[0]);
}
}
}));


// save view state on shutdown
this.storageService.onWillSaveState(() => {
Expand Down