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

Have widget handle KEY_DOWN event #189870

Merged
merged 1 commit into from
Aug 7, 2023
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
17 changes: 10 additions & 7 deletions src/vs/platform/quickinput/browser/quickInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1421,17 +1421,20 @@ export class QuickInputController extends Disposable {
this._register(dom.addDisposableListener(container, dom.EventType.FOCUS, (e: FocusEvent) => {
inputBox.setFocus();
}));
this._register(dom.addDisposableListener(container, dom.EventType.KEY_DOWN, (e: KeyboardEvent) => {
const event = new StandardKeyboardEvent(e);
// TODO: Turn into commands instead of handling KEY_DOWN
this._register(dom.addStandardDisposableListener(container, dom.EventType.KEY_DOWN, (event) => {
if (dom.isAncestor(event.target, widget)) {
return; // Ignore event if target is inside widget to allow the widget to handle the event.
}
switch (event.keyCode) {
case KeyCode.Enter:
dom.EventHelper.stop(e, true);
dom.EventHelper.stop(event, true);
if (this.enabled) {
this.onDidAcceptEmitter.fire();
}
break;
case KeyCode.Escape:
dom.EventHelper.stop(e, true);
dom.EventHelper.stop(event, true);
this.hide(QuickInputHideReason.Gesture);
break;
case KeyCode.Tab:
Expand Down Expand Up @@ -1467,17 +1470,17 @@ export class QuickInputController extends Disposable {
if (event.shiftKey && event.target === stops[0]) {
// Clear the focus from the list in order to allow
// screen readers to read operations in the input box.
dom.EventHelper.stop(e, true);
dom.EventHelper.stop(event, true);
list.clearFocus();
} else if (!event.shiftKey && dom.isAncestor(event.target, stops[stops.length - 1])) {
dom.EventHelper.stop(e, true);
dom.EventHelper.stop(event, true);
stops[0].focus();
}
}
break;
case KeyCode.Space:
if (event.ctrlKey) {
dom.EventHelper.stop(e, true);
dom.EventHelper.stop(event, true);
this.getUI().list.toggleHover();
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@ class AskQuickQuestionAction extends Action2 {
}, 1000 * 30); // 30 seconds
}));

//#endregion

disposableStore.add(this._input.onDidAccept(() => {
this._currentChat?.acceptInput();
}));

disposableStore.add(this._input.onDidTriggerButton((e) => {
if (e === clearButton) {
this._currentChat?.clear();
Expand All @@ -137,6 +131,8 @@ class AskQuickQuestionAction extends Action2 {
}
}));

//#endregion

this._currentChat.focus();

if (query) {
Expand Down