Skip to content

Commit

Permalink
Handle key_up in callout dialog (#15472) (#15485)
Browse files Browse the repository at this point in the history
  • Loading branch information
chlafreniere committed May 14, 2021
1 parent 1d6427c commit 0f5cfdc
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { InputBox } from 'sql/base/browser/ui/inputBox/inputBox';
import { attachCalloutDialogStyler } from 'sql/workbench/common/styler';
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { escapeLabel, escapeUrl } from 'sql/workbench/contrib/notebook/browser/calloutDialog/common/utils';
import { KeyCode } from 'vs/base/common/keyCodes';

export interface ILinkCalloutDialogOptions {
insertTitle?: string,
Expand Down Expand Up @@ -100,6 +101,13 @@ export class LinkCalloutDialog extends Modal {
}

protected renderBody(container: HTMLElement) {
this._register(DOM.addDisposableListener(document, DOM.EventType.KEY_UP, (e: KeyboardEvent) => {
let event = new StandardKeyboardEvent(e);
if (event.equals(KeyCode.Enter)) {
DOM.EventHelper.stop(e, true);
this.hide('ok');
}
}));
let linkContentColumn = DOM.$('.column.insert-link');
DOM.append(container, linkContentColumn);

Expand Down Expand Up @@ -147,16 +155,19 @@ export class LinkCalloutDialog extends Modal {
protected onAccept(e?: StandardKeyboardEvent) {
// EventHelper.stop() will call preventDefault. Without it, text cell will insert an extra newline when pressing enter on dialog
DOM.EventHelper.stop(e, true);
this.insert();
const keyboardEventExists = !!e;
this.insert(keyboardEventExists);
}

protected onClose(e?: StandardKeyboardEvent) {
DOM.EventHelper.stop(e, true);
this.cancel();
}

public insert(): void {
this.hide('ok');
public insert(willHideByKeyboardEvent = false): void {
if (!willHideByKeyboardEvent) {
this.hide('ok');
}
let escapedLabel = escapeLabel(this._linkTextInputBox.value);
let escapedUrl = escapeUrl(this._linkUrlInputBox.value);

Expand Down

0 comments on commit 0f5cfdc

Please sign in to comment.