-
Notifications
You must be signed in to change notification settings - Fork 30.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,16 +14,17 @@ import * as platform from 'vs/base/common/platform'; | |
import { Gesture } from 'vs/base/browser/touch'; | ||
import { KeyCode } from 'vs/base/common/keyCodes'; | ||
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent'; | ||
import { Event, Emitter, EventBufferer, chain, mapEvent, anyEvent } from 'vs/base/common/event'; | ||
import { Event, Emitter, EventBufferer, chain, mapEvent, anyEvent, debounceEvent, reduceEvent } from 'vs/base/common/event'; | ||
import { domEvent } from 'vs/base/browser/event'; | ||
import { IListVirtualDelegate, IListRenderer, IListEvent, IListContextMenuEvent, IListMouseEvent, IListTouchEvent, IListGestureEvent, IIdentityProvider } from './list'; | ||
import { IListVirtualDelegate, IListRenderer, IListEvent, IListContextMenuEvent, IListMouseEvent, IListTouchEvent, IListGestureEvent, IIdentityProvider, ITypeLabelProvider } from './list'; | ||
import { ListView, IListViewOptions } from './listView'; | ||
import { Color } from 'vs/base/common/color'; | ||
import { mixin } from 'vs/base/common/objects'; | ||
import { ScrollbarVisibility } from 'vs/base/common/scrollable'; | ||
import { ISpliceable } from 'vs/base/common/sequence'; | ||
import { CombinedSpliceable } from 'vs/base/browser/ui/list/splice'; | ||
import { clamp } from 'vs/base/common/numbers'; | ||
import { matchesPrefix } from 'vs/base/common/filters'; | ||
|
||
interface ITraitChangeEvent { | ||
indexes: number[]; | ||
|
@@ -322,6 +323,69 @@ class KeyboardController<T> implements IDisposable { | |
} | ||
} | ||
|
||
enum TypeLabelControllerState { | ||
Idle, | ||
Typing | ||
} | ||
|
||
class TypeLabelController<T> implements IDisposable { | ||
|
||
private state: TypeLabelControllerState = TypeLabelControllerState.Idle; | ||
private disposables: IDisposable[] = []; | ||
|
||
constructor( | ||
private list: List<T>, | ||
private view: ListView<T>, | ||
private typeLabelProvider: ITypeLabelProvider<T> | ||
) { | ||
const onChar = chain(domEvent(view.domNode, 'keydown')) | ||
.map(event => new StandardKeyboardEvent(event)) | ||
.filter(event => { | ||
if (event.ctrlKey || event.metaKey || event.altKey) { | ||
return false; | ||
} | ||
|
||
return (event.keyCode >= KeyCode.KEY_A && event.keyCode <= KeyCode.KEY_Z) | ||
|| (event.keyCode >= KeyCode.KEY_0 && event.keyCode <= KeyCode.KEY_9) | ||
|| (event.keyCode >= KeyCode.US_SEMICOLON && event.keyCode <= KeyCode.US_QUOTE); | ||
}) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
joaomoreno
Author
Member
|
||
.map(event => event.browserEvent.key) | ||
.event; | ||
|
||
const onClear = debounceEvent<string, null>(onChar, () => null, 800); | ||
const onInput = reduceEvent<string | null, string | null>(anyEvent(onChar, onClear), (r, i) => i === null ? null : ((r || '') + i)); | ||
|
||
onInput(this.onInput, this, this.disposables); | ||
} | ||
|
||
private onInput(word: string | null): void { | ||
if (!word) { | ||
this.state = TypeLabelControllerState.Idle; | ||
return; | ||
} | ||
|
||
const focus = this.list.getFocus(); | ||
const start = focus.length > 0 ? focus[0] : 0; | ||
const delta = this.state === TypeLabelControllerState.Idle ? 1 : 0; | ||
this.state = TypeLabelControllerState.Typing; | ||
|
||
for (let i = 0; i < this.list.length; i++) { | ||
const index = (start + i + delta) % this.list.length; | ||
const label = this.typeLabelProvider.getTypeLabel(this.view.element(index)); | ||
|
||
if (matchesPrefix(word, label.toString())) { | ||
this.list.setFocus([index]); | ||
this.list.reveal(index); | ||
return; | ||
} | ||
} | ||
} | ||
|
||
dispose() { | ||
this.disposables = dispose(this.disposables); | ||
} | ||
} | ||
|
||
class DOMFocusController<T> implements IDisposable { | ||
|
||
private disposables: IDisposable[] = []; | ||
|
@@ -666,6 +730,7 @@ export class DefaultStyleController implements IStyleController { | |
|
||
export interface IListOptions<T> extends IListViewOptions, IListStyles { | ||
identityProvider?: IIdentityProvider<T>; | ||
typeLabelProvider?: ITypeLabelProvider<T>; | ||
ariaLabel?: string; | ||
mouseSupport?: boolean; | ||
selectOnMouseDown?: boolean; | ||
|
@@ -1002,6 +1067,11 @@ export class List<T> implements ISpliceable<T>, IDisposable { | |
this.disposables.push(controller); | ||
} | ||
|
||
if (options.typeLabelProvider) { | ||
const controller = new TypeLabelController(this, this.view, options.typeLabelProvider); | ||
this.disposables.push(controller); | ||
} | ||
|
||
if (typeof options.mouseSupport === 'boolean' ? options.mouseSupport : true) { | ||
this.disposables.push(new MouseController(this, this.view, options)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Please make this pluggable (maybe keep this as default) because these checks are too weak - been there, done that with the with outline view and breadcrumbs. We do have (in another layer)
IKeybindingService#mightProducePrintableCharacter
and that should be used for better results