提交 fa155b78 编写于 作者: C Christof Marti

Transfer focus to list on arrow-down (#45589)

上级 14fc1c54
...@@ -88,21 +88,7 @@ export class QuickInputService extends Component implements IQuickInputService { ...@@ -88,21 +88,7 @@ export class QuickInputService extends Component implements IQuickInputService {
this.toUnbind.push(this.inputBox.onKeyDown(event => { this.toUnbind.push(this.inputBox.onKeyDown(event => {
switch (event.keyCode) { switch (event.keyCode) {
case KeyCode.DownArrow: case KeyCode.DownArrow:
this.checkboxList.focus('Next'); this.checkboxList.domFocus();
break;
case KeyCode.UpArrow:
this.checkboxList.focus('Previous');
break;
case KeyCode.PageDown:
this.checkboxList.focus('NextPage');
break;
case KeyCode.PageUp:
this.checkboxList.focus('PreviousPage');
break;
case KeyCode.Space:
if (event.ctrlKey) {
this.checkboxList.toggleCheckbox();
}
break; break;
} }
})); }));
...@@ -123,6 +109,12 @@ export class QuickInputService extends Component implements IQuickInputService { ...@@ -123,6 +109,12 @@ export class QuickInputService extends Component implements IQuickInputService {
this.toUnbind.push(this.checkboxList.onSelectedCountChanged(count => { this.toUnbind.push(this.checkboxList.onSelectedCountChanged(count => {
this.count.setCount(count); this.count.setCount(count);
})); }));
this.toUnbind.push(this.checkboxList.onLeave(() => {
// Defer to avoid the input field reacting to the triggering key.
setTimeout(() => {
this.inputBox.setFocus();
}, 0);
}));
this.toUnbind.push(dom.addDisposableListener(this.container, 'focusout', (e: FocusEvent) => { this.toUnbind.push(dom.addDisposableListener(this.container, 'focusout', (e: FocusEvent) => {
for (let element = <Element>e.relatedTarget; element; element = element.parentElement) { for (let element = <Element>e.relatedTarget; element; element = element.parentElement) {
...@@ -173,7 +165,7 @@ export class QuickInputService extends Component implements IQuickInputService { ...@@ -173,7 +165,7 @@ export class QuickInputService extends Component implements IQuickInputService {
this.inputBox.setValue(''); this.inputBox.setValue('');
// TODO: Localize shortcut. // TODO: Localize shortcut.
this.inputBox.setPlaceholder(options.placeHolder ? localize('quickInput.ctrlSpaceToSelectWithPlaceholder', "{1} ({0} to toggle)", 'Ctrl+Space', options.placeHolder) : localize('quickInput.ctrlSpaceToSelect', "{0} to toggle", 'Ctrl+Space')); this.inputBox.setPlaceholder(options.placeHolder || '');
// TODO: Progress indication. // TODO: Progress indication.
this.checkboxList.setElements(await picks); this.checkboxList.setElements(await picks);
this.checkboxList.matchOnDescription = options.matchOnDescription; this.checkboxList.matchOnDescription = options.matchOnDescription;
......
...@@ -149,6 +149,8 @@ export class QuickInputCheckboxList { ...@@ -149,6 +149,8 @@ export class QuickInputCheckboxList {
onAllVisibleSelectedChanged: Event<boolean> = this._onAllVisibleSelectedChanged.event; onAllVisibleSelectedChanged: Event<boolean> = this._onAllVisibleSelectedChanged.event;
private _onSelectedCountChanged = new Emitter<number>(); // TODO: Debounce private _onSelectedCountChanged = new Emitter<number>(); // TODO: Debounce
onSelectedCountChanged: Event<number> = this._onSelectedCountChanged.event; onSelectedCountChanged: Event<number> = this._onSelectedCountChanged.event;
private _onLeave = new Emitter<void>();
onLeave: Event<void> = this._onLeave.event;
private elementDisposables: IDisposable[] = []; private elementDisposables: IDisposable[] = [];
private disposables: IDisposable[] = []; private disposables: IDisposable[] = [];
...@@ -165,8 +167,16 @@ export class QuickInputCheckboxList { ...@@ -165,8 +167,16 @@ export class QuickInputCheckboxList {
this.disposables.push(this.list); this.disposables.push(this.list);
this.disposables.push(this.list.onKeyDown(e => { this.disposables.push(this.list.onKeyDown(e => {
const event = new StandardKeyboardEvent(e); const event = new StandardKeyboardEvent(e);
if (event.keyCode === KeyCode.Space) { switch (event.keyCode) {
this.toggleCheckbox(); case KeyCode.Space:
this.toggleCheckbox();
break;
case KeyCode.UpArrow:
const focus = this.list.getFocus();
if (focus.length === 1 && focus[0] === 0) {
this._onLeave.fire();
}
break;
} }
})); }));
} }
...@@ -212,6 +222,10 @@ export class QuickInputCheckboxList { ...@@ -212,6 +222,10 @@ export class QuickInputCheckboxList {
this.list['focus' + what](); this.list['focus' + what]();
} }
domFocus() {
this.list.domFocus();
}
layout(): void { layout(): void {
this.list.layout(); this.list.layout();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册